{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1. [同时选取DataFrame多列](#%E5%90%8C%E6%97%B6%E9%80%89%E5%8F%96DataFrame%E5%A4%9A%E5%88%97)\n",
    "2. [搭配方法选取列](#%E6%90%AD%E9%85%8D%E6%96%B9%E6%B3%95%E9%80%89%E5%8F%96%E5%88%97)\n",
    "3. [对列名排序方便数据处理](#%E5%AF%B9%E5%88%97%E5%90%8D%E6%8E%92%E5%BA%8F%E6%96%B9%E4%BE%BF%E6%95%B0%E6%8D%AE%E5%A4%84%E7%90%86)\n",
    "4. [对整个DataFrame进行操作](#%E5%AF%B9%E6%95%B4%E4%B8%AADataFrame%E8%BF%9B%E8%A1%8C%E6%93%8D%E4%BD%9C)\n",
    "5. [DataFrame方法的链式调用](#DataFrame%E6%96%B9%E6%B3%95%E7%9A%84%E9%93%BE%E5%BC%8F%E8%B0%83%E7%94%A8)\n",
    "6. [DataFrame的操作符](#DataFrame%E7%9A%84%E6%93%8D%E4%BD%9C%E7%AC%A6)\n",
    "7. [比较丢失的值](#%E6%AF%94%E8%BE%83%E4%B8%A2%E5%A4%B1%E7%9A%84%E5%80%BC%EF%BC%88%E7%A9%BA%E5%80%BC%EF%BC%89)\n",
    "8. [DataFrame数据操作的方向性](#DataFrame%E6%95%B0%E6%8D%AE%E6%93%8D%E4%BD%9C%E7%9A%84%E6%96%B9%E5%90%91%E6%80%A7)\n",
    "9. [计算大学校园多元化](#%E8%AE%A1%E7%AE%97%E5%A4%A7%E5%AD%A6%E6%A0%A1%E5%9B%AD%E5%A4%9A%E5%85%83%E5%8C%96)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "pd.options.display.max_rows = 10\n",
    "pd.options.display.max_columns = 40 # 最多显示40列"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 同时选取DataFrame多列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>actor_1_name</th>\n",
       "      <th>actor_2_name</th>\n",
       "      <th>actor_3_name</th>\n",
       "      <th>director_name</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>CCH Pounder</td>\n",
       "      <td>Joel David Moore</td>\n",
       "      <td>Wes Studi</td>\n",
       "      <td>James Cameron</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Johnny Depp</td>\n",
       "      <td>Orlando Bloom</td>\n",
       "      <td>Jack Davenport</td>\n",
       "      <td>Gore Verbinski</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Christoph Waltz</td>\n",
       "      <td>Rory Kinnear</td>\n",
       "      <td>Stephanie Sigman</td>\n",
       "      <td>Sam Mendes</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Tom Hardy</td>\n",
       "      <td>Christian Bale</td>\n",
       "      <td>Joseph Gordon-Levitt</td>\n",
       "      <td>Christopher Nolan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Doug Walker</td>\n",
       "      <td>Rob Walker</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Doug Walker</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      actor_1_name      actor_2_name          actor_3_name      director_name\n",
       "0      CCH Pounder  Joel David Moore             Wes Studi      James Cameron\n",
       "1      Johnny Depp     Orlando Bloom        Jack Davenport     Gore Verbinski\n",
       "2  Christoph Waltz      Rory Kinnear      Stephanie Sigman         Sam Mendes\n",
       "3        Tom Hardy    Christian Bale  Joseph Gordon-Levitt  Christopher Nolan\n",
       "4      Doug Walker        Rob Walker                   NaN        Doug Walker"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# DataFrame的下标是先列后行，与普通二维数组不一样！\n",
    "# df['col']选取的是一列，df[['c1', 'c2', 'c3']]选取的是多列。\n",
    "movie = pd.read_csv('data/movie.csv')\n",
    "movie_actor_director = movie[['actor_1_name', 'actor_2_name', 'actor_3_name', 'director_name']]\n",
    "movie_actor_director.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>director_name</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>James Cameron</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Gore Verbinski</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Sam Mendes</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Christopher Nolan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Doug Walker</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       director_name\n",
       "0      James Cameron\n",
       "1     Gore Verbinski\n",
       "2         Sam Mendes\n",
       "3  Christopher Nolan\n",
       "4        Doug Walker"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movie[['director_name']].head() # 只选取一列也可以这么写"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "ename": "KeyError",
     "evalue": "('actor_1_name', 'actor_2_name', 'actor_3_name', 'director_name')",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mKeyError\u001b[0m                                  Traceback (most recent call last)",
      "\u001b[1;32mc:\\users\\lin\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\pandas\\core\\indexes\\base.py\u001b[0m in \u001b[0;36mget_loc\u001b[1;34m(self, key, method, tolerance)\u001b[0m\n\u001b[0;32m   2645\u001b[0m             \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 2646\u001b[1;33m                 \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_engine\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_loc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   2647\u001b[0m             \u001b[1;32mexcept\u001b[0m \u001b[0mKeyError\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mpandas\\_libs\\index.pyx\u001b[0m in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[1;34m()\u001b[0m\n",
      "\u001b[1;32mpandas\\_libs\\index.pyx\u001b[0m in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[1;34m()\u001b[0m\n",
      "\u001b[1;32mpandas\\_libs\\hashtable_class_helper.pxi\u001b[0m in \u001b[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[1;34m()\u001b[0m\n",
      "\u001b[1;32mpandas\\_libs\\hashtable_class_helper.pxi\u001b[0m in \u001b[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[1;34m()\u001b[0m\n",
      "\u001b[1;31mKeyError\u001b[0m: ('actor_1_name', 'actor_2_name', 'actor_3_name', 'director_name')",
      "\nDuring handling of the above exception, another exception occurred:\n",
      "\u001b[1;31mKeyError\u001b[0m                                  Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-4-cfaefcd4a811>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mmovie\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'actor_1_name'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'actor_2_name'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'actor_3_name'\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;34m'director_name'\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;31m# 错误的写法！！！\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;32mc:\\users\\lin\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\pandas\\core\\frame.py\u001b[0m in \u001b[0;36m__getitem__\u001b[1;34m(self, key)\u001b[0m\n\u001b[0;32m   2798\u001b[0m             \u001b[1;32mif\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcolumns\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mnlevels\u001b[0m \u001b[1;33m>\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   2799\u001b[0m                 \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_getitem_multilevel\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 2800\u001b[1;33m             \u001b[0mindexer\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcolumns\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_loc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   2801\u001b[0m             \u001b[1;32mif\u001b[0m \u001b[0mis_integer\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mindexer\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   2802\u001b[0m                 \u001b[0mindexer\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;33m[\u001b[0m\u001b[0mindexer\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\users\\lin\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\pandas\\core\\indexes\\base.py\u001b[0m in \u001b[0;36mget_loc\u001b[1;34m(self, key, method, tolerance)\u001b[0m\n\u001b[0;32m   2646\u001b[0m                 \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_engine\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_loc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   2647\u001b[0m             \u001b[1;32mexcept\u001b[0m \u001b[0mKeyError\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 2648\u001b[1;33m                 \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_engine\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_loc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_maybe_cast_indexer\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m   2649\u001b[0m         \u001b[0mindexer\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mget_indexer\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mkey\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mmethod\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mmethod\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mtolerance\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mtolerance\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   2650\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[0mindexer\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mndim\u001b[0m \u001b[1;33m>\u001b[0m \u001b[1;36m1\u001b[0m \u001b[1;32mor\u001b[0m \u001b[0mindexer\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0msize\u001b[0m \u001b[1;33m>\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mpandas\\_libs\\index.pyx\u001b[0m in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[1;34m()\u001b[0m\n",
      "\u001b[1;32mpandas\\_libs\\index.pyx\u001b[0m in \u001b[0;36mpandas._libs.index.IndexEngine.get_loc\u001b[1;34m()\u001b[0m\n",
      "\u001b[1;32mpandas\\_libs\\hashtable_class_helper.pxi\u001b[0m in \u001b[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[1;34m()\u001b[0m\n",
      "\u001b[1;32mpandas\\_libs\\hashtable_class_helper.pxi\u001b[0m in \u001b[0;36mpandas._libs.hashtable.PyObjectHashTable.get_item\u001b[1;34m()\u001b[0m\n",
      "\u001b[1;31mKeyError\u001b[0m: ('actor_1_name', 'actor_2_name', 'actor_3_name', 'director_name')"
     ]
    }
   ],
   "source": [
    "movie['actor_1_name', 'actor_2_name', 'actor_3_name', 'director_name'] # 错误的写法！！！"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>actor_1_name</th>\n",
       "      <th>actor_2_name</th>\n",
       "      <th>actor_3_name</th>\n",
       "      <th>director_name</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>CCH Pounder</td>\n",
       "      <td>Joel David Moore</td>\n",
       "      <td>Wes Studi</td>\n",
       "      <td>James Cameron</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Johnny Depp</td>\n",
       "      <td>Orlando Bloom</td>\n",
       "      <td>Jack Davenport</td>\n",
       "      <td>Gore Verbinski</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Christoph Waltz</td>\n",
       "      <td>Rory Kinnear</td>\n",
       "      <td>Stephanie Sigman</td>\n",
       "      <td>Sam Mendes</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Tom Hardy</td>\n",
       "      <td>Christian Bale</td>\n",
       "      <td>Joseph Gordon-Levitt</td>\n",
       "      <td>Christopher Nolan</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Doug Walker</td>\n",
       "      <td>Rob Walker</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Doug Walker</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      actor_1_name      actor_2_name          actor_3_name      director_name\n",
       "0      CCH Pounder  Joel David Moore             Wes Studi      James Cameron\n",
       "1      Johnny Depp     Orlando Bloom        Jack Davenport     Gore Verbinski\n",
       "2  Christoph Waltz      Rory Kinnear      Stephanie Sigman         Sam Mendes\n",
       "3        Tom Hardy    Christian Bale  Joseph Gordon-Levitt  Christopher Nolan\n",
       "4      Doug Walker        Rob Walker                   NaN        Doug Walker"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "cols =['actor_1_name', 'actor_2_name', 'actor_3_name', 'director_name']\n",
    "movie_actor_director = movie[cols] # 如果列多的话可以写成2行，代码更清晰。\n",
    "movie_actor_director.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 搭配方法选取列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "float64    13\n",
       "object     11\n",
       "int64       3\n",
       "dtype: int64"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movie = pd.read_csv('data/movie.csv', index_col='movie_title') # 指定movie_title作为索引列\n",
    "movie.dtypes.value_counts() # 对各列的数据类型进行统计"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>num_voted_users</th>\n",
       "      <th>cast_total_facebook_likes</th>\n",
       "      <th>movie_facebook_likes</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>movie_title</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Avatar</th>\n",
       "      <td>886204</td>\n",
       "      <td>4834</td>\n",
       "      <td>33000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Pirates of the Caribbean: At World's End</th>\n",
       "      <td>471220</td>\n",
       "      <td>48350</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Spectre</th>\n",
       "      <td>275868</td>\n",
       "      <td>11700</td>\n",
       "      <td>85000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>The Dark Knight Rises</th>\n",
       "      <td>1144337</td>\n",
       "      <td>106759</td>\n",
       "      <td>164000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Star Wars: Episode VII - The Force Awakens</th>\n",
       "      <td>8</td>\n",
       "      <td>143</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                            num_voted_users  \\\n",
       "movie_title                                                   \n",
       "Avatar                                               886204   \n",
       "Pirates of the Caribbean: At World's End             471220   \n",
       "Spectre                                              275868   \n",
       "The Dark Knight Rises                               1144337   \n",
       "Star Wars: Episode VII - The Force Awakens                8   \n",
       "\n",
       "                                            cast_total_facebook_likes  \\\n",
       "movie_title                                                             \n",
       "Avatar                                                           4834   \n",
       "Pirates of the Caribbean: At World's End                        48350   \n",
       "Spectre                                                         11700   \n",
       "The Dark Knight Rises                                          106759   \n",
       "Star Wars: Episode VII - The Force Awakens                        143   \n",
       "\n",
       "                                            movie_facebook_likes  \n",
       "movie_title                                                       \n",
       "Avatar                                                     33000  \n",
       "Pirates of the Caribbean: At World's End                       0  \n",
       "Spectre                                                    85000  \n",
       "The Dark Knight Rises                                     164000  \n",
       "Star Wars: Episode VII - The Force Awakens                     0  "
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movie.select_dtypes(include=['int64']).head() # 只选取int64类型的列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>num_critic_for_reviews</th>\n",
       "      <th>duration</th>\n",
       "      <th>director_facebook_likes</th>\n",
       "      <th>actor_3_facebook_likes</th>\n",
       "      <th>actor_1_facebook_likes</th>\n",
       "      <th>gross</th>\n",
       "      <th>num_voted_users</th>\n",
       "      <th>cast_total_facebook_likes</th>\n",
       "      <th>facenumber_in_poster</th>\n",
       "      <th>num_user_for_reviews</th>\n",
       "      <th>budget</th>\n",
       "      <th>title_year</th>\n",
       "      <th>actor_2_facebook_likes</th>\n",
       "      <th>imdb_score</th>\n",
       "      <th>aspect_ratio</th>\n",
       "      <th>movie_facebook_likes</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>movie_title</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Avatar</th>\n",
       "      <td>723.0</td>\n",
       "      <td>178.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>855.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>760505847.0</td>\n",
       "      <td>886204</td>\n",
       "      <td>4834</td>\n",
       "      <td>0.0</td>\n",
       "      <td>3054.0</td>\n",
       "      <td>237000000.0</td>\n",
       "      <td>2009.0</td>\n",
       "      <td>936.0</td>\n",
       "      <td>7.9</td>\n",
       "      <td>1.78</td>\n",
       "      <td>33000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Pirates of the Caribbean: At World's End</th>\n",
       "      <td>302.0</td>\n",
       "      <td>169.0</td>\n",
       "      <td>563.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>40000.0</td>\n",
       "      <td>309404152.0</td>\n",
       "      <td>471220</td>\n",
       "      <td>48350</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1238.0</td>\n",
       "      <td>300000000.0</td>\n",
       "      <td>2007.0</td>\n",
       "      <td>5000.0</td>\n",
       "      <td>7.1</td>\n",
       "      <td>2.35</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Spectre</th>\n",
       "      <td>602.0</td>\n",
       "      <td>148.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>161.0</td>\n",
       "      <td>11000.0</td>\n",
       "      <td>200074175.0</td>\n",
       "      <td>275868</td>\n",
       "      <td>11700</td>\n",
       "      <td>1.0</td>\n",
       "      <td>994.0</td>\n",
       "      <td>245000000.0</td>\n",
       "      <td>2015.0</td>\n",
       "      <td>393.0</td>\n",
       "      <td>6.8</td>\n",
       "      <td>2.35</td>\n",
       "      <td>85000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>The Dark Knight Rises</th>\n",
       "      <td>813.0</td>\n",
       "      <td>164.0</td>\n",
       "      <td>22000.0</td>\n",
       "      <td>23000.0</td>\n",
       "      <td>27000.0</td>\n",
       "      <td>448130642.0</td>\n",
       "      <td>1144337</td>\n",
       "      <td>106759</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2701.0</td>\n",
       "      <td>250000000.0</td>\n",
       "      <td>2012.0</td>\n",
       "      <td>23000.0</td>\n",
       "      <td>8.5</td>\n",
       "      <td>2.35</td>\n",
       "      <td>164000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Star Wars: Episode VII - The Force Awakens</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>131.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>131.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>8</td>\n",
       "      <td>143</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>12.0</td>\n",
       "      <td>7.1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                            num_critic_for_reviews  duration  \\\n",
       "movie_title                                                                    \n",
       "Avatar                                                       723.0     178.0   \n",
       "Pirates of the Caribbean: At World's End                     302.0     169.0   \n",
       "Spectre                                                      602.0     148.0   \n",
       "The Dark Knight Rises                                        813.0     164.0   \n",
       "Star Wars: Episode VII - The Force Awakens                     NaN       NaN   \n",
       "\n",
       "                                            director_facebook_likes  \\\n",
       "movie_title                                                           \n",
       "Avatar                                                          0.0   \n",
       "Pirates of the Caribbean: At World's End                      563.0   \n",
       "Spectre                                                         0.0   \n",
       "The Dark Knight Rises                                       22000.0   \n",
       "Star Wars: Episode VII - The Force Awakens                    131.0   \n",
       "\n",
       "                                            actor_3_facebook_likes  \\\n",
       "movie_title                                                          \n",
       "Avatar                                                       855.0   \n",
       "Pirates of the Caribbean: At World's End                    1000.0   \n",
       "Spectre                                                      161.0   \n",
       "The Dark Knight Rises                                      23000.0   \n",
       "Star Wars: Episode VII - The Force Awakens                     NaN   \n",
       "\n",
       "                                            actor_1_facebook_likes  \\\n",
       "movie_title                                                          \n",
       "Avatar                                                      1000.0   \n",
       "Pirates of the Caribbean: At World's End                   40000.0   \n",
       "Spectre                                                    11000.0   \n",
       "The Dark Knight Rises                                      27000.0   \n",
       "Star Wars: Episode VII - The Force Awakens                   131.0   \n",
       "\n",
       "                                                  gross  num_voted_users  \\\n",
       "movie_title                                                                \n",
       "Avatar                                      760505847.0           886204   \n",
       "Pirates of the Caribbean: At World's End    309404152.0           471220   \n",
       "Spectre                                     200074175.0           275868   \n",
       "The Dark Knight Rises                       448130642.0          1144337   \n",
       "Star Wars: Episode VII - The Force Awakens          NaN                8   \n",
       "\n",
       "                                            cast_total_facebook_likes  \\\n",
       "movie_title                                                             \n",
       "Avatar                                                           4834   \n",
       "Pirates of the Caribbean: At World's End                        48350   \n",
       "Spectre                                                         11700   \n",
       "The Dark Knight Rises                                          106759   \n",
       "Star Wars: Episode VII - The Force Awakens                        143   \n",
       "\n",
       "                                            facenumber_in_poster  \\\n",
       "movie_title                                                        \n",
       "Avatar                                                       0.0   \n",
       "Pirates of the Caribbean: At World's End                     0.0   \n",
       "Spectre                                                      1.0   \n",
       "The Dark Knight Rises                                        0.0   \n",
       "Star Wars: Episode VII - The Force Awakens                   0.0   \n",
       "\n",
       "                                            num_user_for_reviews       budget  \\\n",
       "movie_title                                                                     \n",
       "Avatar                                                    3054.0  237000000.0   \n",
       "Pirates of the Caribbean: At World's End                  1238.0  300000000.0   \n",
       "Spectre                                                    994.0  245000000.0   \n",
       "The Dark Knight Rises                                     2701.0  250000000.0   \n",
       "Star Wars: Episode VII - The Force Awakens                   NaN          NaN   \n",
       "\n",
       "                                            title_year  \\\n",
       "movie_title                                              \n",
       "Avatar                                          2009.0   \n",
       "Pirates of the Caribbean: At World's End        2007.0   \n",
       "Spectre                                         2015.0   \n",
       "The Dark Knight Rises                           2012.0   \n",
       "Star Wars: Episode VII - The Force Awakens         NaN   \n",
       "\n",
       "                                            actor_2_facebook_likes  \\\n",
       "movie_title                                                          \n",
       "Avatar                                                       936.0   \n",
       "Pirates of the Caribbean: At World's End                    5000.0   \n",
       "Spectre                                                      393.0   \n",
       "The Dark Knight Rises                                      23000.0   \n",
       "Star Wars: Episode VII - The Force Awakens                    12.0   \n",
       "\n",
       "                                            imdb_score  aspect_ratio  \\\n",
       "movie_title                                                            \n",
       "Avatar                                             7.9          1.78   \n",
       "Pirates of the Caribbean: At World's End           7.1          2.35   \n",
       "Spectre                                            6.8          2.35   \n",
       "The Dark Knight Rises                              8.5          2.35   \n",
       "Star Wars: Episode VII - The Force Awakens         7.1           NaN   \n",
       "\n",
       "                                            movie_facebook_likes  \n",
       "movie_title                                                       \n",
       "Avatar                                                     33000  \n",
       "Pirates of the Caribbean: At World's End                       0  \n",
       "Spectre                                                    85000  \n",
       "The Dark Knight Rises                                     164000  \n",
       "Star Wars: Episode VII - The Force Awakens                     0  "
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movie.select_dtypes(include=['number']).head() # 选取所有number类型的列，包含int64与float64。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>director_facebook_likes</th>\n",
       "      <th>actor_3_facebook_likes</th>\n",
       "      <th>actor_1_facebook_likes</th>\n",
       "      <th>cast_total_facebook_likes</th>\n",
       "      <th>actor_2_facebook_likes</th>\n",
       "      <th>movie_facebook_likes</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>movie_title</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Avatar</th>\n",
       "      <td>0.0</td>\n",
       "      <td>855.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>4834</td>\n",
       "      <td>936.0</td>\n",
       "      <td>33000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Pirates of the Caribbean: At World's End</th>\n",
       "      <td>563.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>40000.0</td>\n",
       "      <td>48350</td>\n",
       "      <td>5000.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Spectre</th>\n",
       "      <td>0.0</td>\n",
       "      <td>161.0</td>\n",
       "      <td>11000.0</td>\n",
       "      <td>11700</td>\n",
       "      <td>393.0</td>\n",
       "      <td>85000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>The Dark Knight Rises</th>\n",
       "      <td>22000.0</td>\n",
       "      <td>23000.0</td>\n",
       "      <td>27000.0</td>\n",
       "      <td>106759</td>\n",
       "      <td>23000.0</td>\n",
       "      <td>164000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Star Wars: Episode VII - The Force Awakens</th>\n",
       "      <td>131.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>131.0</td>\n",
       "      <td>143</td>\n",
       "      <td>12.0</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                            director_facebook_likes  \\\n",
       "movie_title                                                           \n",
       "Avatar                                                          0.0   \n",
       "Pirates of the Caribbean: At World's End                      563.0   \n",
       "Spectre                                                         0.0   \n",
       "The Dark Knight Rises                                       22000.0   \n",
       "Star Wars: Episode VII - The Force Awakens                    131.0   \n",
       "\n",
       "                                            actor_3_facebook_likes  \\\n",
       "movie_title                                                          \n",
       "Avatar                                                       855.0   \n",
       "Pirates of the Caribbean: At World's End                    1000.0   \n",
       "Spectre                                                      161.0   \n",
       "The Dark Knight Rises                                      23000.0   \n",
       "Star Wars: Episode VII - The Force Awakens                     NaN   \n",
       "\n",
       "                                            actor_1_facebook_likes  \\\n",
       "movie_title                                                          \n",
       "Avatar                                                      1000.0   \n",
       "Pirates of the Caribbean: At World's End                   40000.0   \n",
       "Spectre                                                    11000.0   \n",
       "The Dark Knight Rises                                      27000.0   \n",
       "Star Wars: Episode VII - The Force Awakens                   131.0   \n",
       "\n",
       "                                            cast_total_facebook_likes  \\\n",
       "movie_title                                                             \n",
       "Avatar                                                           4834   \n",
       "Pirates of the Caribbean: At World's End                        48350   \n",
       "Spectre                                                         11700   \n",
       "The Dark Knight Rises                                          106759   \n",
       "Star Wars: Episode VII - The Force Awakens                        143   \n",
       "\n",
       "                                            actor_2_facebook_likes  \\\n",
       "movie_title                                                          \n",
       "Avatar                                                       936.0   \n",
       "Pirates of the Caribbean: At World's End                    5000.0   \n",
       "Spectre                                                      393.0   \n",
       "The Dark Knight Rises                                      23000.0   \n",
       "Star Wars: Episode VII - The Force Awakens                    12.0   \n",
       "\n",
       "                                            movie_facebook_likes  \n",
       "movie_title                                                       \n",
       "Avatar                                                     33000  \n",
       "Pirates of the Caribbean: At World's End                       0  \n",
       "Spectre                                                    85000  \n",
       "The Dark Knight Rises                                     164000  \n",
       "Star Wars: Episode VII - The Force Awakens                     0  "
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movie.filter(like='facebook').head() # 只选取名字包含facebook的列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>actor_3_facebook_likes</th>\n",
       "      <th>actor_2_name</th>\n",
       "      <th>actor_1_facebook_likes</th>\n",
       "      <th>actor_1_name</th>\n",
       "      <th>actor_3_name</th>\n",
       "      <th>actor_2_facebook_likes</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>movie_title</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Avatar</th>\n",
       "      <td>855.0</td>\n",
       "      <td>Joel David Moore</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>CCH Pounder</td>\n",
       "      <td>Wes Studi</td>\n",
       "      <td>936.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Pirates of the Caribbean: At World's End</th>\n",
       "      <td>1000.0</td>\n",
       "      <td>Orlando Bloom</td>\n",
       "      <td>40000.0</td>\n",
       "      <td>Johnny Depp</td>\n",
       "      <td>Jack Davenport</td>\n",
       "      <td>5000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Spectre</th>\n",
       "      <td>161.0</td>\n",
       "      <td>Rory Kinnear</td>\n",
       "      <td>11000.0</td>\n",
       "      <td>Christoph Waltz</td>\n",
       "      <td>Stephanie Sigman</td>\n",
       "      <td>393.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>The Dark Knight Rises</th>\n",
       "      <td>23000.0</td>\n",
       "      <td>Christian Bale</td>\n",
       "      <td>27000.0</td>\n",
       "      <td>Tom Hardy</td>\n",
       "      <td>Joseph Gordon-Levitt</td>\n",
       "      <td>23000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Star Wars: Episode VII - The Force Awakens</th>\n",
       "      <td>NaN</td>\n",
       "      <td>Rob Walker</td>\n",
       "      <td>131.0</td>\n",
       "      <td>Doug Walker</td>\n",
       "      <td>NaN</td>\n",
       "      <td>12.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                            actor_3_facebook_likes  \\\n",
       "movie_title                                                          \n",
       "Avatar                                                       855.0   \n",
       "Pirates of the Caribbean: At World's End                    1000.0   \n",
       "Spectre                                                      161.0   \n",
       "The Dark Knight Rises                                      23000.0   \n",
       "Star Wars: Episode VII - The Force Awakens                     NaN   \n",
       "\n",
       "                                                actor_2_name  \\\n",
       "movie_title                                                    \n",
       "Avatar                                      Joel David Moore   \n",
       "Pirates of the Caribbean: At World's End       Orlando Bloom   \n",
       "Spectre                                         Rory Kinnear   \n",
       "The Dark Knight Rises                         Christian Bale   \n",
       "Star Wars: Episode VII - The Force Awakens        Rob Walker   \n",
       "\n",
       "                                            actor_1_facebook_likes  \\\n",
       "movie_title                                                          \n",
       "Avatar                                                      1000.0   \n",
       "Pirates of the Caribbean: At World's End                   40000.0   \n",
       "Spectre                                                    11000.0   \n",
       "The Dark Knight Rises                                      27000.0   \n",
       "Star Wars: Episode VII - The Force Awakens                   131.0   \n",
       "\n",
       "                                               actor_1_name  \\\n",
       "movie_title                                                   \n",
       "Avatar                                          CCH Pounder   \n",
       "Pirates of the Caribbean: At World's End        Johnny Depp   \n",
       "Spectre                                     Christoph Waltz   \n",
       "The Dark Knight Rises                             Tom Hardy   \n",
       "Star Wars: Episode VII - The Force Awakens      Doug Walker   \n",
       "\n",
       "                                                    actor_3_name  \\\n",
       "movie_title                                                        \n",
       "Avatar                                                 Wes Studi   \n",
       "Pirates of the Caribbean: At World's End          Jack Davenport   \n",
       "Spectre                                         Stephanie Sigman   \n",
       "The Dark Knight Rises                       Joseph Gordon-Levitt   \n",
       "Star Wars: Episode VII - The Force Awakens                   NaN   \n",
       "\n",
       "                                            actor_2_facebook_likes  \n",
       "movie_title                                                         \n",
       "Avatar                                                       936.0  \n",
       "Pirates of the Caribbean: At World's End                    5000.0  \n",
       "Spectre                                                      393.0  \n",
       "The Dark Knight Rises                                      23000.0  \n",
       "Star Wars: Episode VII - The Force Awakens                    12.0  "
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movie.filter(regex='\\d').head() # 使用正则表达式进行筛选，列名必须包含数字。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>actor_1_name</th>\n",
       "      <th>actor_2_name</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>movie_title</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Avatar</th>\n",
       "      <td>CCH Pounder</td>\n",
       "      <td>Joel David Moore</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Pirates of the Caribbean: At World's End</th>\n",
       "      <td>Johnny Depp</td>\n",
       "      <td>Orlando Bloom</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Spectre</th>\n",
       "      <td>Christoph Waltz</td>\n",
       "      <td>Rory Kinnear</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>The Dark Knight Rises</th>\n",
       "      <td>Tom Hardy</td>\n",
       "      <td>Christian Bale</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Star Wars: Episode VII - The Force Awakens</th>\n",
       "      <td>Doug Walker</td>\n",
       "      <td>Rob Walker</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                               actor_1_name      actor_2_name\n",
       "movie_title                                                                  \n",
       "Avatar                                          CCH Pounder  Joel David Moore\n",
       "Pirates of the Caribbean: At World's End        Johnny Depp     Orlando Bloom\n",
       "Spectre                                     Christoph Waltz      Rory Kinnear\n",
       "The Dark Knight Rises                             Tom Hardy    Christian Bale\n",
       "Star Wars: Episode VII - The Force Awakens      Doug Walker        Rob Walker"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movie.filter(items=['actor_1_name', 'actor_2_name', 'asdf']).head() # 选取指定名字的列，匹配不到就忽略。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 对列名排序方便数据处理"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>color</th>\n",
       "      <th>director_name</th>\n",
       "      <th>num_critic_for_reviews</th>\n",
       "      <th>duration</th>\n",
       "      <th>director_facebook_likes</th>\n",
       "      <th>actor_3_facebook_likes</th>\n",
       "      <th>actor_2_name</th>\n",
       "      <th>actor_1_facebook_likes</th>\n",
       "      <th>gross</th>\n",
       "      <th>genres</th>\n",
       "      <th>actor_1_name</th>\n",
       "      <th>movie_title</th>\n",
       "      <th>num_voted_users</th>\n",
       "      <th>cast_total_facebook_likes</th>\n",
       "      <th>actor_3_name</th>\n",
       "      <th>facenumber_in_poster</th>\n",
       "      <th>plot_keywords</th>\n",
       "      <th>movie_imdb_link</th>\n",
       "      <th>num_user_for_reviews</th>\n",
       "      <th>language</th>\n",
       "      <th>country</th>\n",
       "      <th>content_rating</th>\n",
       "      <th>budget</th>\n",
       "      <th>title_year</th>\n",
       "      <th>actor_2_facebook_likes</th>\n",
       "      <th>imdb_score</th>\n",
       "      <th>aspect_ratio</th>\n",
       "      <th>movie_facebook_likes</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Color</td>\n",
       "      <td>James Cameron</td>\n",
       "      <td>723.0</td>\n",
       "      <td>178.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>855.0</td>\n",
       "      <td>Joel David Moore</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>760505847.0</td>\n",
       "      <td>Action|Adventure|Fantasy|Sci-Fi</td>\n",
       "      <td>CCH Pounder</td>\n",
       "      <td>Avatar</td>\n",
       "      <td>886204</td>\n",
       "      <td>4834</td>\n",
       "      <td>Wes Studi</td>\n",
       "      <td>0.0</td>\n",
       "      <td>avatar|future|marine|native|paraplegic</td>\n",
       "      <td>http://www.imdb.com/title/tt0499549/?ref_=fn_t...</td>\n",
       "      <td>3054.0</td>\n",
       "      <td>English</td>\n",
       "      <td>USA</td>\n",
       "      <td>PG-13</td>\n",
       "      <td>237000000.0</td>\n",
       "      <td>2009.0</td>\n",
       "      <td>936.0</td>\n",
       "      <td>7.9</td>\n",
       "      <td>1.78</td>\n",
       "      <td>33000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Color</td>\n",
       "      <td>Gore Verbinski</td>\n",
       "      <td>302.0</td>\n",
       "      <td>169.0</td>\n",
       "      <td>563.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>Orlando Bloom</td>\n",
       "      <td>40000.0</td>\n",
       "      <td>309404152.0</td>\n",
       "      <td>Action|Adventure|Fantasy</td>\n",
       "      <td>Johnny Depp</td>\n",
       "      <td>Pirates of the Caribbean: At World's End</td>\n",
       "      <td>471220</td>\n",
       "      <td>48350</td>\n",
       "      <td>Jack Davenport</td>\n",
       "      <td>0.0</td>\n",
       "      <td>goddess|marriage ceremony|marriage proposal|pi...</td>\n",
       "      <td>http://www.imdb.com/title/tt0449088/?ref_=fn_t...</td>\n",
       "      <td>1238.0</td>\n",
       "      <td>English</td>\n",
       "      <td>USA</td>\n",
       "      <td>PG-13</td>\n",
       "      <td>300000000.0</td>\n",
       "      <td>2007.0</td>\n",
       "      <td>5000.0</td>\n",
       "      <td>7.1</td>\n",
       "      <td>2.35</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Color</td>\n",
       "      <td>Sam Mendes</td>\n",
       "      <td>602.0</td>\n",
       "      <td>148.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>161.0</td>\n",
       "      <td>Rory Kinnear</td>\n",
       "      <td>11000.0</td>\n",
       "      <td>200074175.0</td>\n",
       "      <td>Action|Adventure|Thriller</td>\n",
       "      <td>Christoph Waltz</td>\n",
       "      <td>Spectre</td>\n",
       "      <td>275868</td>\n",
       "      <td>11700</td>\n",
       "      <td>Stephanie Sigman</td>\n",
       "      <td>1.0</td>\n",
       "      <td>bomb|espionage|sequel|spy|terrorist</td>\n",
       "      <td>http://www.imdb.com/title/tt2379713/?ref_=fn_t...</td>\n",
       "      <td>994.0</td>\n",
       "      <td>English</td>\n",
       "      <td>UK</td>\n",
       "      <td>PG-13</td>\n",
       "      <td>245000000.0</td>\n",
       "      <td>2015.0</td>\n",
       "      <td>393.0</td>\n",
       "      <td>6.8</td>\n",
       "      <td>2.35</td>\n",
       "      <td>85000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Color</td>\n",
       "      <td>Christopher Nolan</td>\n",
       "      <td>813.0</td>\n",
       "      <td>164.0</td>\n",
       "      <td>22000.0</td>\n",
       "      <td>23000.0</td>\n",
       "      <td>Christian Bale</td>\n",
       "      <td>27000.0</td>\n",
       "      <td>448130642.0</td>\n",
       "      <td>Action|Thriller</td>\n",
       "      <td>Tom Hardy</td>\n",
       "      <td>The Dark Knight Rises</td>\n",
       "      <td>1144337</td>\n",
       "      <td>106759</td>\n",
       "      <td>Joseph Gordon-Levitt</td>\n",
       "      <td>0.0</td>\n",
       "      <td>deception|imprisonment|lawlessness|police offi...</td>\n",
       "      <td>http://www.imdb.com/title/tt1345836/?ref_=fn_t...</td>\n",
       "      <td>2701.0</td>\n",
       "      <td>English</td>\n",
       "      <td>USA</td>\n",
       "      <td>PG-13</td>\n",
       "      <td>250000000.0</td>\n",
       "      <td>2012.0</td>\n",
       "      <td>23000.0</td>\n",
       "      <td>8.5</td>\n",
       "      <td>2.35</td>\n",
       "      <td>164000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>NaN</td>\n",
       "      <td>Doug Walker</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>131.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Rob Walker</td>\n",
       "      <td>131.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Documentary</td>\n",
       "      <td>Doug Walker</td>\n",
       "      <td>Star Wars: Episode VII - The Force Awakens</td>\n",
       "      <td>8</td>\n",
       "      <td>143</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>http://www.imdb.com/title/tt5289954/?ref_=fn_t...</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>12.0</td>\n",
       "      <td>7.1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   color      director_name  num_critic_for_reviews  duration  \\\n",
       "0  Color      James Cameron                   723.0     178.0   \n",
       "1  Color     Gore Verbinski                   302.0     169.0   \n",
       "2  Color         Sam Mendes                   602.0     148.0   \n",
       "3  Color  Christopher Nolan                   813.0     164.0   \n",
       "4    NaN        Doug Walker                     NaN       NaN   \n",
       "\n",
       "   director_facebook_likes  actor_3_facebook_likes      actor_2_name  \\\n",
       "0                      0.0                   855.0  Joel David Moore   \n",
       "1                    563.0                  1000.0     Orlando Bloom   \n",
       "2                      0.0                   161.0      Rory Kinnear   \n",
       "3                  22000.0                 23000.0    Christian Bale   \n",
       "4                    131.0                     NaN        Rob Walker   \n",
       "\n",
       "   actor_1_facebook_likes        gross                           genres  \\\n",
       "0                  1000.0  760505847.0  Action|Adventure|Fantasy|Sci-Fi   \n",
       "1                 40000.0  309404152.0         Action|Adventure|Fantasy   \n",
       "2                 11000.0  200074175.0        Action|Adventure|Thriller   \n",
       "3                 27000.0  448130642.0                  Action|Thriller   \n",
       "4                   131.0          NaN                      Documentary   \n",
       "\n",
       "      actor_1_name                                 movie_title  \\\n",
       "0      CCH Pounder                                      Avatar   \n",
       "1      Johnny Depp    Pirates of the Caribbean: At World's End   \n",
       "2  Christoph Waltz                                     Spectre   \n",
       "3        Tom Hardy                       The Dark Knight Rises   \n",
       "4      Doug Walker  Star Wars: Episode VII - The Force Awakens   \n",
       "\n",
       "   num_voted_users  cast_total_facebook_likes          actor_3_name  \\\n",
       "0           886204                       4834             Wes Studi   \n",
       "1           471220                      48350        Jack Davenport   \n",
       "2           275868                      11700      Stephanie Sigman   \n",
       "3          1144337                     106759  Joseph Gordon-Levitt   \n",
       "4                8                        143                   NaN   \n",
       "\n",
       "   facenumber_in_poster                                      plot_keywords  \\\n",
       "0                   0.0             avatar|future|marine|native|paraplegic   \n",
       "1                   0.0  goddess|marriage ceremony|marriage proposal|pi...   \n",
       "2                   1.0                bomb|espionage|sequel|spy|terrorist   \n",
       "3                   0.0  deception|imprisonment|lawlessness|police offi...   \n",
       "4                   0.0                                                NaN   \n",
       "\n",
       "                                     movie_imdb_link  num_user_for_reviews  \\\n",
       "0  http://www.imdb.com/title/tt0499549/?ref_=fn_t...                3054.0   \n",
       "1  http://www.imdb.com/title/tt0449088/?ref_=fn_t...                1238.0   \n",
       "2  http://www.imdb.com/title/tt2379713/?ref_=fn_t...                 994.0   \n",
       "3  http://www.imdb.com/title/tt1345836/?ref_=fn_t...                2701.0   \n",
       "4  http://www.imdb.com/title/tt5289954/?ref_=fn_t...                   NaN   \n",
       "\n",
       "  language country content_rating       budget  title_year  \\\n",
       "0  English     USA          PG-13  237000000.0      2009.0   \n",
       "1  English     USA          PG-13  300000000.0      2007.0   \n",
       "2  English      UK          PG-13  245000000.0      2015.0   \n",
       "3  English     USA          PG-13  250000000.0      2012.0   \n",
       "4      NaN     NaN            NaN          NaN         NaN   \n",
       "\n",
       "   actor_2_facebook_likes  imdb_score  aspect_ratio  movie_facebook_likes  \n",
       "0                   936.0         7.9          1.78                 33000  \n",
       "1                  5000.0         7.1          2.35                     0  \n",
       "2                   393.0         6.8          2.35                 85000  \n",
       "3                 23000.0         8.5          2.35                164000  \n",
       "4                    12.0         7.1           NaN                     0  "
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movie = pd.read_csv('data/movie.csv')\n",
    "movie.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['color', 'director_name', 'num_critic_for_reviews', 'duration',\n",
       "       'director_facebook_likes', 'actor_3_facebook_likes', 'actor_2_name',\n",
       "       'actor_1_facebook_likes', 'gross', 'genres', 'actor_1_name',\n",
       "       'movie_title', 'num_voted_users', 'cast_total_facebook_likes',\n",
       "       'actor_3_name', 'facenumber_in_poster', 'plot_keywords',\n",
       "       'movie_imdb_link', 'num_user_for_reviews', 'language', 'country',\n",
       "       'content_rating', 'budget', 'title_year', 'actor_2_facebook_likes',\n",
       "       'imdb_score', 'aspect_ratio', 'movie_facebook_likes'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movie.columns"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [],
   "source": [
    "# 根据列名的含义进行分组\n",
    "disc_core = ['movie_title','title_year', 'content_rating','genres']\n",
    "disc_people = ['director_name','actor_1_name', 'actor_2_name','actor_3_name']\n",
    "disc_other = ['color','country','language','plot_keywords','movie_imdb_link']\n",
    "cont_fb = ['director_facebook_likes','actor_1_facebook_likes','actor_2_facebook_likes',\n",
    "           'actor_3_facebook_likes', 'cast_total_facebook_likes', 'movie_facebook_likes']\n",
    "cont_finance = ['budget','gross']\n",
    "cont_num_reviews = ['num_voted_users','num_user_for_reviews', 'num_critic_for_reviews']\n",
    "cont_other = ['imdb_score','duration', 'aspect_ratio', 'facenumber_in_poster']"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "new_col_order = disc_core + \\\n",
    "                disc_people + disc_other + \\\n",
    "                cont_fb + \\\n",
    "                cont_finance + \\\n",
    "                cont_num_reviews + \\\n",
    "                cont_other\n",
    "# 列名的顺序就是new_col_order里元素的顺序\n",
    "# set()是把数组去重变成集合，检查数据是否一致，防止写漏了。\n",
    "set(movie.columns) == set(new_col_order)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>movie_title</th>\n",
       "      <th>title_year</th>\n",
       "      <th>content_rating</th>\n",
       "      <th>genres</th>\n",
       "      <th>director_name</th>\n",
       "      <th>actor_1_name</th>\n",
       "      <th>actor_2_name</th>\n",
       "      <th>actor_3_name</th>\n",
       "      <th>color</th>\n",
       "      <th>country</th>\n",
       "      <th>language</th>\n",
       "      <th>plot_keywords</th>\n",
       "      <th>movie_imdb_link</th>\n",
       "      <th>director_facebook_likes</th>\n",
       "      <th>actor_1_facebook_likes</th>\n",
       "      <th>actor_2_facebook_likes</th>\n",
       "      <th>actor_3_facebook_likes</th>\n",
       "      <th>cast_total_facebook_likes</th>\n",
       "      <th>movie_facebook_likes</th>\n",
       "      <th>budget</th>\n",
       "      <th>gross</th>\n",
       "      <th>num_voted_users</th>\n",
       "      <th>num_user_for_reviews</th>\n",
       "      <th>num_critic_for_reviews</th>\n",
       "      <th>imdb_score</th>\n",
       "      <th>duration</th>\n",
       "      <th>aspect_ratio</th>\n",
       "      <th>facenumber_in_poster</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Avatar</td>\n",
       "      <td>2009.0</td>\n",
       "      <td>PG-13</td>\n",
       "      <td>Action|Adventure|Fantasy|Sci-Fi</td>\n",
       "      <td>James Cameron</td>\n",
       "      <td>CCH Pounder</td>\n",
       "      <td>Joel David Moore</td>\n",
       "      <td>Wes Studi</td>\n",
       "      <td>Color</td>\n",
       "      <td>USA</td>\n",
       "      <td>English</td>\n",
       "      <td>avatar|future|marine|native|paraplegic</td>\n",
       "      <td>http://www.imdb.com/title/tt0499549/?ref_=fn_t...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>936.0</td>\n",
       "      <td>855.0</td>\n",
       "      <td>4834</td>\n",
       "      <td>33000</td>\n",
       "      <td>237000000.0</td>\n",
       "      <td>760505847.0</td>\n",
       "      <td>886204</td>\n",
       "      <td>3054.0</td>\n",
       "      <td>723.0</td>\n",
       "      <td>7.9</td>\n",
       "      <td>178.0</td>\n",
       "      <td>1.78</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Pirates of the Caribbean: At World's End</td>\n",
       "      <td>2007.0</td>\n",
       "      <td>PG-13</td>\n",
       "      <td>Action|Adventure|Fantasy</td>\n",
       "      <td>Gore Verbinski</td>\n",
       "      <td>Johnny Depp</td>\n",
       "      <td>Orlando Bloom</td>\n",
       "      <td>Jack Davenport</td>\n",
       "      <td>Color</td>\n",
       "      <td>USA</td>\n",
       "      <td>English</td>\n",
       "      <td>goddess|marriage ceremony|marriage proposal|pi...</td>\n",
       "      <td>http://www.imdb.com/title/tt0449088/?ref_=fn_t...</td>\n",
       "      <td>563.0</td>\n",
       "      <td>40000.0</td>\n",
       "      <td>5000.0</td>\n",
       "      <td>1000.0</td>\n",
       "      <td>48350</td>\n",
       "      <td>0</td>\n",
       "      <td>300000000.0</td>\n",
       "      <td>309404152.0</td>\n",
       "      <td>471220</td>\n",
       "      <td>1238.0</td>\n",
       "      <td>302.0</td>\n",
       "      <td>7.1</td>\n",
       "      <td>169.0</td>\n",
       "      <td>2.35</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Spectre</td>\n",
       "      <td>2015.0</td>\n",
       "      <td>PG-13</td>\n",
       "      <td>Action|Adventure|Thriller</td>\n",
       "      <td>Sam Mendes</td>\n",
       "      <td>Christoph Waltz</td>\n",
       "      <td>Rory Kinnear</td>\n",
       "      <td>Stephanie Sigman</td>\n",
       "      <td>Color</td>\n",
       "      <td>UK</td>\n",
       "      <td>English</td>\n",
       "      <td>bomb|espionage|sequel|spy|terrorist</td>\n",
       "      <td>http://www.imdb.com/title/tt2379713/?ref_=fn_t...</td>\n",
       "      <td>0.0</td>\n",
       "      <td>11000.0</td>\n",
       "      <td>393.0</td>\n",
       "      <td>161.0</td>\n",
       "      <td>11700</td>\n",
       "      <td>85000</td>\n",
       "      <td>245000000.0</td>\n",
       "      <td>200074175.0</td>\n",
       "      <td>275868</td>\n",
       "      <td>994.0</td>\n",
       "      <td>602.0</td>\n",
       "      <td>6.8</td>\n",
       "      <td>148.0</td>\n",
       "      <td>2.35</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>The Dark Knight Rises</td>\n",
       "      <td>2012.0</td>\n",
       "      <td>PG-13</td>\n",
       "      <td>Action|Thriller</td>\n",
       "      <td>Christopher Nolan</td>\n",
       "      <td>Tom Hardy</td>\n",
       "      <td>Christian Bale</td>\n",
       "      <td>Joseph Gordon-Levitt</td>\n",
       "      <td>Color</td>\n",
       "      <td>USA</td>\n",
       "      <td>English</td>\n",
       "      <td>deception|imprisonment|lawlessness|police offi...</td>\n",
       "      <td>http://www.imdb.com/title/tt1345836/?ref_=fn_t...</td>\n",
       "      <td>22000.0</td>\n",
       "      <td>27000.0</td>\n",
       "      <td>23000.0</td>\n",
       "      <td>23000.0</td>\n",
       "      <td>106759</td>\n",
       "      <td>164000</td>\n",
       "      <td>250000000.0</td>\n",
       "      <td>448130642.0</td>\n",
       "      <td>1144337</td>\n",
       "      <td>2701.0</td>\n",
       "      <td>813.0</td>\n",
       "      <td>8.5</td>\n",
       "      <td>164.0</td>\n",
       "      <td>2.35</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Star Wars: Episode VII - The Force Awakens</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Documentary</td>\n",
       "      <td>Doug Walker</td>\n",
       "      <td>Doug Walker</td>\n",
       "      <td>Rob Walker</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>http://www.imdb.com/title/tt5289954/?ref_=fn_t...</td>\n",
       "      <td>131.0</td>\n",
       "      <td>131.0</td>\n",
       "      <td>12.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>143</td>\n",
       "      <td>0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>8</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>7.1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                  movie_title  title_year content_rating  \\\n",
       "0                                      Avatar      2009.0          PG-13   \n",
       "1    Pirates of the Caribbean: At World's End      2007.0          PG-13   \n",
       "2                                     Spectre      2015.0          PG-13   \n",
       "3                       The Dark Knight Rises      2012.0          PG-13   \n",
       "4  Star Wars: Episode VII - The Force Awakens         NaN            NaN   \n",
       "\n",
       "                            genres      director_name     actor_1_name  \\\n",
       "0  Action|Adventure|Fantasy|Sci-Fi      James Cameron      CCH Pounder   \n",
       "1         Action|Adventure|Fantasy     Gore Verbinski      Johnny Depp   \n",
       "2        Action|Adventure|Thriller         Sam Mendes  Christoph Waltz   \n",
       "3                  Action|Thriller  Christopher Nolan        Tom Hardy   \n",
       "4                      Documentary        Doug Walker      Doug Walker   \n",
       "\n",
       "       actor_2_name          actor_3_name  color country language  \\\n",
       "0  Joel David Moore             Wes Studi  Color     USA  English   \n",
       "1     Orlando Bloom        Jack Davenport  Color     USA  English   \n",
       "2      Rory Kinnear      Stephanie Sigman  Color      UK  English   \n",
       "3    Christian Bale  Joseph Gordon-Levitt  Color     USA  English   \n",
       "4        Rob Walker                   NaN    NaN     NaN      NaN   \n",
       "\n",
       "                                       plot_keywords  \\\n",
       "0             avatar|future|marine|native|paraplegic   \n",
       "1  goddess|marriage ceremony|marriage proposal|pi...   \n",
       "2                bomb|espionage|sequel|spy|terrorist   \n",
       "3  deception|imprisonment|lawlessness|police offi...   \n",
       "4                                                NaN   \n",
       "\n",
       "                                     movie_imdb_link  director_facebook_likes  \\\n",
       "0  http://www.imdb.com/title/tt0499549/?ref_=fn_t...                      0.0   \n",
       "1  http://www.imdb.com/title/tt0449088/?ref_=fn_t...                    563.0   \n",
       "2  http://www.imdb.com/title/tt2379713/?ref_=fn_t...                      0.0   \n",
       "3  http://www.imdb.com/title/tt1345836/?ref_=fn_t...                  22000.0   \n",
       "4  http://www.imdb.com/title/tt5289954/?ref_=fn_t...                    131.0   \n",
       "\n",
       "   actor_1_facebook_likes  actor_2_facebook_likes  actor_3_facebook_likes  \\\n",
       "0                  1000.0                   936.0                   855.0   \n",
       "1                 40000.0                  5000.0                  1000.0   \n",
       "2                 11000.0                   393.0                   161.0   \n",
       "3                 27000.0                 23000.0                 23000.0   \n",
       "4                   131.0                    12.0                     NaN   \n",
       "\n",
       "   cast_total_facebook_likes  movie_facebook_likes       budget        gross  \\\n",
       "0                       4834                 33000  237000000.0  760505847.0   \n",
       "1                      48350                     0  300000000.0  309404152.0   \n",
       "2                      11700                 85000  245000000.0  200074175.0   \n",
       "3                     106759                164000  250000000.0  448130642.0   \n",
       "4                        143                     0          NaN          NaN   \n",
       "\n",
       "   num_voted_users  num_user_for_reviews  num_critic_for_reviews  imdb_score  \\\n",
       "0           886204                3054.0                   723.0         7.9   \n",
       "1           471220                1238.0                   302.0         7.1   \n",
       "2           275868                 994.0                   602.0         6.8   \n",
       "3          1144337                2701.0                   813.0         8.5   \n",
       "4                8                   NaN                     NaN         7.1   \n",
       "\n",
       "   duration  aspect_ratio  facenumber_in_poster  \n",
       "0     178.0          1.78                   0.0  \n",
       "1     169.0          2.35                   0.0  \n",
       "2     148.0          2.35                   1.0  \n",
       "3     164.0          2.35                   0.0  \n",
       "4       NaN           NaN                   0.0  "
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movie2 = movie[new_col_order] # 返回新的DataFrame，列的顺序根据new_col_order排列。\n",
    "movie2.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 对整个DataFrame进行操作"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "(4916, 28)"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.options.display.max_rows = 8\n",
    "movie = pd.read_csv('data/movie.csv')\n",
    "movie.shape # 返回一个tuple（只读数组），对应行数，列数。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "137648"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movie.size # 行数 * 列数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 19,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movie.ndim # 维度，目前的例子是2维。只要脑洞够大，3维4维都可以。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4916"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "len(movie) # 数据行数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "color                     4897\n",
       "director_name             4814\n",
       "num_critic_for_reviews    4867\n",
       "duration                  4901\n",
       "                          ... \n",
       "actor_2_facebook_likes    4903\n",
       "imdb_score                4916\n",
       "aspect_ratio              4590\n",
       "movie_facebook_likes      4916\n",
       "Length: 28, dtype: int64"
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movie.count() # 每一列数据非空值的数量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "num_critic_for_reviews        1\n",
       "duration                      7\n",
       "director_facebook_likes       0\n",
       "actor_3_facebook_likes        0\n",
       "                           ... \n",
       "actor_2_facebook_likes        0\n",
       "imdb_score                  1.6\n",
       "aspect_ratio               1.18\n",
       "movie_facebook_likes          0\n",
       "Length: 19, dtype: object"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movie.min() # 每一列的最小值，仅针可比较类型，比如数字或字符串。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<class 'pandas.core.series.Series'>\n"
     ]
    }
   ],
   "source": [
    "m = movie.min()\n",
    "print(type(m))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "num_critic_for_reviews 1.0\n",
      "duration 7.0\n",
      "director_facebook_likes 0.0\n",
      "actor_3_facebook_likes 0.0\n",
      "actor_1_facebook_likes 0.0\n",
      "gross 162.0\n",
      "genres Action\n",
      "movie_title #Horror\n",
      "num_voted_users 5\n",
      "cast_total_facebook_likes 0\n",
      "facenumber_in_poster 0.0\n",
      "movie_imdb_link http://www.imdb.com/title/tt0006864/?ref_=fn_tt_tt_1\n",
      "num_user_for_reviews 1.0\n",
      "budget 218.0\n",
      "title_year 1916.0\n",
      "actor_2_facebook_likes 0.0\n",
      "imdb_score 1.6\n",
      "aspect_ratio 1.18\n",
      "movie_facebook_likes 0\n"
     ]
    }
   ],
   "source": [
    "for k in m.keys(): # Series既可以用下标索引，也可以用key访问元素。类似于字典与数字的混合。\n",
    "    print(k, m[k])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>num_critic_for_reviews</th>\n",
       "      <th>duration</th>\n",
       "      <th>director_facebook_likes</th>\n",
       "      <th>actor_3_facebook_likes</th>\n",
       "      <th>actor_1_facebook_likes</th>\n",
       "      <th>gross</th>\n",
       "      <th>num_voted_users</th>\n",
       "      <th>cast_total_facebook_likes</th>\n",
       "      <th>facenumber_in_poster</th>\n",
       "      <th>num_user_for_reviews</th>\n",
       "      <th>budget</th>\n",
       "      <th>title_year</th>\n",
       "      <th>actor_2_facebook_likes</th>\n",
       "      <th>imdb_score</th>\n",
       "      <th>aspect_ratio</th>\n",
       "      <th>movie_facebook_likes</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>4867.000000</td>\n",
       "      <td>4901.000000</td>\n",
       "      <td>4814.000000</td>\n",
       "      <td>4893.000000</td>\n",
       "      <td>4909.000000</td>\n",
       "      <td>4.054000e+03</td>\n",
       "      <td>4.916000e+03</td>\n",
       "      <td>4916.000000</td>\n",
       "      <td>4903.000000</td>\n",
       "      <td>4895.000000</td>\n",
       "      <td>4.432000e+03</td>\n",
       "      <td>4810.000000</td>\n",
       "      <td>4903.000000</td>\n",
       "      <td>4916.000000</td>\n",
       "      <td>4590.000000</td>\n",
       "      <td>4916.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>137.988905</td>\n",
       "      <td>107.090798</td>\n",
       "      <td>691.014541</td>\n",
       "      <td>631.276313</td>\n",
       "      <td>6494.488491</td>\n",
       "      <td>4.764451e+07</td>\n",
       "      <td>8.264492e+04</td>\n",
       "      <td>9579.815907</td>\n",
       "      <td>1.377320</td>\n",
       "      <td>267.668846</td>\n",
       "      <td>3.654749e+07</td>\n",
       "      <td>2002.447609</td>\n",
       "      <td>1621.923516</td>\n",
       "      <td>6.437429</td>\n",
       "      <td>2.222349</td>\n",
       "      <td>7348.294142</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>120.239379</td>\n",
       "      <td>25.286015</td>\n",
       "      <td>2832.954125</td>\n",
       "      <td>1625.874802</td>\n",
       "      <td>15106.986884</td>\n",
       "      <td>6.737255e+07</td>\n",
       "      <td>1.383222e+05</td>\n",
       "      <td>18164.316990</td>\n",
       "      <td>2.023826</td>\n",
       "      <td>372.934839</td>\n",
       "      <td>1.002427e+08</td>\n",
       "      <td>12.453977</td>\n",
       "      <td>4011.299523</td>\n",
       "      <td>1.127802</td>\n",
       "      <td>1.402940</td>\n",
       "      <td>19206.016458</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>7.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.620000e+02</td>\n",
       "      <td>5.000000e+00</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>2.180000e+02</td>\n",
       "      <td>1916.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.600000</td>\n",
       "      <td>1.180000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25%</th>\n",
       "      <td>49.000000</td>\n",
       "      <td>93.000000</td>\n",
       "      <td>7.000000</td>\n",
       "      <td>132.000000</td>\n",
       "      <td>607.000000</td>\n",
       "      <td>5.019656e+06</td>\n",
       "      <td>8.361750e+03</td>\n",
       "      <td>1394.750000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>64.000000</td>\n",
       "      <td>6.000000e+06</td>\n",
       "      <td>1999.000000</td>\n",
       "      <td>277.000000</td>\n",
       "      <td>5.800000</td>\n",
       "      <td>1.850000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>108.000000</td>\n",
       "      <td>103.000000</td>\n",
       "      <td>48.000000</td>\n",
       "      <td>366.000000</td>\n",
       "      <td>982.000000</td>\n",
       "      <td>2.504396e+07</td>\n",
       "      <td>3.313250e+04</td>\n",
       "      <td>3049.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>153.000000</td>\n",
       "      <td>1.985000e+07</td>\n",
       "      <td>2005.000000</td>\n",
       "      <td>593.000000</td>\n",
       "      <td>6.600000</td>\n",
       "      <td>2.350000</td>\n",
       "      <td>159.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>75%</th>\n",
       "      <td>191.000000</td>\n",
       "      <td>118.000000</td>\n",
       "      <td>189.750000</td>\n",
       "      <td>633.000000</td>\n",
       "      <td>11000.000000</td>\n",
       "      <td>6.110841e+07</td>\n",
       "      <td>9.377275e+04</td>\n",
       "      <td>13616.750000</td>\n",
       "      <td>2.000000</td>\n",
       "      <td>320.500000</td>\n",
       "      <td>4.300000e+07</td>\n",
       "      <td>2011.000000</td>\n",
       "      <td>912.000000</td>\n",
       "      <td>7.200000</td>\n",
       "      <td>2.350000</td>\n",
       "      <td>2000.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>813.000000</td>\n",
       "      <td>511.000000</td>\n",
       "      <td>23000.000000</td>\n",
       "      <td>23000.000000</td>\n",
       "      <td>640000.000000</td>\n",
       "      <td>7.605058e+08</td>\n",
       "      <td>1.689764e+06</td>\n",
       "      <td>656730.000000</td>\n",
       "      <td>43.000000</td>\n",
       "      <td>5060.000000</td>\n",
       "      <td>4.200000e+09</td>\n",
       "      <td>2016.000000</td>\n",
       "      <td>137000.000000</td>\n",
       "      <td>9.500000</td>\n",
       "      <td>16.000000</td>\n",
       "      <td>349000.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       num_critic_for_reviews     duration  director_facebook_likes  \\\n",
       "count             4867.000000  4901.000000              4814.000000   \n",
       "mean               137.988905   107.090798               691.014541   \n",
       "std                120.239379    25.286015              2832.954125   \n",
       "min                  1.000000     7.000000                 0.000000   \n",
       "25%                 49.000000    93.000000                 7.000000   \n",
       "50%                108.000000   103.000000                48.000000   \n",
       "75%                191.000000   118.000000               189.750000   \n",
       "max                813.000000   511.000000             23000.000000   \n",
       "\n",
       "       actor_3_facebook_likes  actor_1_facebook_likes         gross  \\\n",
       "count             4893.000000             4909.000000  4.054000e+03   \n",
       "mean               631.276313             6494.488491  4.764451e+07   \n",
       "std               1625.874802            15106.986884  6.737255e+07   \n",
       "min                  0.000000                0.000000  1.620000e+02   \n",
       "25%                132.000000              607.000000  5.019656e+06   \n",
       "50%                366.000000              982.000000  2.504396e+07   \n",
       "75%                633.000000            11000.000000  6.110841e+07   \n",
       "max              23000.000000           640000.000000  7.605058e+08   \n",
       "\n",
       "       num_voted_users  cast_total_facebook_likes  facenumber_in_poster  \\\n",
       "count     4.916000e+03                4916.000000           4903.000000   \n",
       "mean      8.264492e+04                9579.815907              1.377320   \n",
       "std       1.383222e+05               18164.316990              2.023826   \n",
       "min       5.000000e+00                   0.000000              0.000000   \n",
       "25%       8.361750e+03                1394.750000              0.000000   \n",
       "50%       3.313250e+04                3049.000000              1.000000   \n",
       "75%       9.377275e+04               13616.750000              2.000000   \n",
       "max       1.689764e+06              656730.000000             43.000000   \n",
       "\n",
       "       num_user_for_reviews        budget   title_year  \\\n",
       "count           4895.000000  4.432000e+03  4810.000000   \n",
       "mean             267.668846  3.654749e+07  2002.447609   \n",
       "std              372.934839  1.002427e+08    12.453977   \n",
       "min                1.000000  2.180000e+02  1916.000000   \n",
       "25%               64.000000  6.000000e+06  1999.000000   \n",
       "50%              153.000000  1.985000e+07  2005.000000   \n",
       "75%              320.500000  4.300000e+07  2011.000000   \n",
       "max             5060.000000  4.200000e+09  2016.000000   \n",
       "\n",
       "       actor_2_facebook_likes   imdb_score  aspect_ratio  movie_facebook_likes  \n",
       "count             4903.000000  4916.000000   4590.000000           4916.000000  \n",
       "mean              1621.923516     6.437429      2.222349           7348.294142  \n",
       "std               4011.299523     1.127802      1.402940          19206.016458  \n",
       "min                  0.000000     1.600000      1.180000              0.000000  \n",
       "25%                277.000000     5.800000      1.850000              0.000000  \n",
       "50%                593.000000     6.600000      2.350000            159.000000  \n",
       "75%                912.000000     7.200000      2.350000           2000.000000  \n",
       "max             137000.000000     9.500000     16.000000         349000.000000  "
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movie.describe() # 快速的查看各列统计信息"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>num_critic_for_reviews</th>\n",
       "      <th>duration</th>\n",
       "      <th>director_facebook_likes</th>\n",
       "      <th>actor_3_facebook_likes</th>\n",
       "      <th>actor_1_facebook_likes</th>\n",
       "      <th>gross</th>\n",
       "      <th>num_voted_users</th>\n",
       "      <th>cast_total_facebook_likes</th>\n",
       "      <th>facenumber_in_poster</th>\n",
       "      <th>num_user_for_reviews</th>\n",
       "      <th>budget</th>\n",
       "      <th>title_year</th>\n",
       "      <th>actor_2_facebook_likes</th>\n",
       "      <th>imdb_score</th>\n",
       "      <th>aspect_ratio</th>\n",
       "      <th>movie_facebook_likes</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>count</th>\n",
       "      <td>4867.000000</td>\n",
       "      <td>4901.000000</td>\n",
       "      <td>4814.000000</td>\n",
       "      <td>4893.000000</td>\n",
       "      <td>4909.000000</td>\n",
       "      <td>4.054000e+03</td>\n",
       "      <td>4.916000e+03</td>\n",
       "      <td>4916.000000</td>\n",
       "      <td>4903.000000</td>\n",
       "      <td>4895.000000</td>\n",
       "      <td>4.432000e+03</td>\n",
       "      <td>4810.000000</td>\n",
       "      <td>4903.000000</td>\n",
       "      <td>4916.000000</td>\n",
       "      <td>4590.000000</td>\n",
       "      <td>4916.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>mean</th>\n",
       "      <td>137.988905</td>\n",
       "      <td>107.090798</td>\n",
       "      <td>691.014541</td>\n",
       "      <td>631.276313</td>\n",
       "      <td>6494.488491</td>\n",
       "      <td>4.764451e+07</td>\n",
       "      <td>8.264492e+04</td>\n",
       "      <td>9579.815907</td>\n",
       "      <td>1.377320</td>\n",
       "      <td>267.668846</td>\n",
       "      <td>3.654749e+07</td>\n",
       "      <td>2002.447609</td>\n",
       "      <td>1621.923516</td>\n",
       "      <td>6.437429</td>\n",
       "      <td>2.222349</td>\n",
       "      <td>7348.294142</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>std</th>\n",
       "      <td>120.239379</td>\n",
       "      <td>25.286015</td>\n",
       "      <td>2832.954125</td>\n",
       "      <td>1625.874802</td>\n",
       "      <td>15106.986884</td>\n",
       "      <td>6.737255e+07</td>\n",
       "      <td>1.383222e+05</td>\n",
       "      <td>18164.316990</td>\n",
       "      <td>2.023826</td>\n",
       "      <td>372.934839</td>\n",
       "      <td>1.002427e+08</td>\n",
       "      <td>12.453977</td>\n",
       "      <td>4011.299523</td>\n",
       "      <td>1.127802</td>\n",
       "      <td>1.402940</td>\n",
       "      <td>19206.016458</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>min</th>\n",
       "      <td>1.000000</td>\n",
       "      <td>7.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.620000e+02</td>\n",
       "      <td>5.000000e+00</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>2.180000e+02</td>\n",
       "      <td>1916.000000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>1.600000</td>\n",
       "      <td>1.180000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>30%</th>\n",
       "      <td>60.000000</td>\n",
       "      <td>95.000000</td>\n",
       "      <td>11.000000</td>\n",
       "      <td>176.000000</td>\n",
       "      <td>694.000000</td>\n",
       "      <td>7.914069e+06</td>\n",
       "      <td>1.186450e+04</td>\n",
       "      <td>1684.500000</td>\n",
       "      <td>0.000000</td>\n",
       "      <td>80.000000</td>\n",
       "      <td>8.000000e+06</td>\n",
       "      <td>2000.000000</td>\n",
       "      <td>345.000000</td>\n",
       "      <td>6.000000</td>\n",
       "      <td>1.850000</td>\n",
       "      <td>0.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>50%</th>\n",
       "      <td>108.000000</td>\n",
       "      <td>103.000000</td>\n",
       "      <td>48.000000</td>\n",
       "      <td>366.000000</td>\n",
       "      <td>982.000000</td>\n",
       "      <td>2.504396e+07</td>\n",
       "      <td>3.313250e+04</td>\n",
       "      <td>3049.000000</td>\n",
       "      <td>1.000000</td>\n",
       "      <td>153.000000</td>\n",
       "      <td>1.985000e+07</td>\n",
       "      <td>2005.000000</td>\n",
       "      <td>593.000000</td>\n",
       "      <td>6.600000</td>\n",
       "      <td>2.350000</td>\n",
       "      <td>159.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>99%</th>\n",
       "      <td>546.680000</td>\n",
       "      <td>189.000000</td>\n",
       "      <td>16000.000000</td>\n",
       "      <td>11000.000000</td>\n",
       "      <td>44920.000000</td>\n",
       "      <td>3.264128e+08</td>\n",
       "      <td>6.815846e+05</td>\n",
       "      <td>62413.900000</td>\n",
       "      <td>8.000000</td>\n",
       "      <td>1999.240000</td>\n",
       "      <td>2.000000e+08</td>\n",
       "      <td>2016.000000</td>\n",
       "      <td>17000.000000</td>\n",
       "      <td>8.500000</td>\n",
       "      <td>4.000000</td>\n",
       "      <td>93850.000000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>max</th>\n",
       "      <td>813.000000</td>\n",
       "      <td>511.000000</td>\n",
       "      <td>23000.000000</td>\n",
       "      <td>23000.000000</td>\n",
       "      <td>640000.000000</td>\n",
       "      <td>7.605058e+08</td>\n",
       "      <td>1.689764e+06</td>\n",
       "      <td>656730.000000</td>\n",
       "      <td>43.000000</td>\n",
       "      <td>5060.000000</td>\n",
       "      <td>4.200000e+09</td>\n",
       "      <td>2016.000000</td>\n",
       "      <td>137000.000000</td>\n",
       "      <td>9.500000</td>\n",
       "      <td>16.000000</td>\n",
       "      <td>349000.000000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>9 rows × 16 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "       num_critic_for_reviews     duration  director_facebook_likes  \\\n",
       "count             4867.000000  4901.000000              4814.000000   \n",
       "mean               137.988905   107.090798               691.014541   \n",
       "std                120.239379    25.286015              2832.954125   \n",
       "min                  1.000000     7.000000                 0.000000   \n",
       "...                       ...          ...                      ...   \n",
       "30%                 60.000000    95.000000                11.000000   \n",
       "50%                108.000000   103.000000                48.000000   \n",
       "99%                546.680000   189.000000             16000.000000   \n",
       "max                813.000000   511.000000             23000.000000   \n",
       "\n",
       "       actor_3_facebook_likes  actor_1_facebook_likes         gross  \\\n",
       "count             4893.000000             4909.000000  4.054000e+03   \n",
       "mean               631.276313             6494.488491  4.764451e+07   \n",
       "std               1625.874802            15106.986884  6.737255e+07   \n",
       "min                  0.000000                0.000000  1.620000e+02   \n",
       "...                       ...                     ...           ...   \n",
       "30%                176.000000              694.000000  7.914069e+06   \n",
       "50%                366.000000              982.000000  2.504396e+07   \n",
       "99%              11000.000000            44920.000000  3.264128e+08   \n",
       "max              23000.000000           640000.000000  7.605058e+08   \n",
       "\n",
       "       num_voted_users  cast_total_facebook_likes  facenumber_in_poster  \\\n",
       "count     4.916000e+03                4916.000000           4903.000000   \n",
       "mean      8.264492e+04                9579.815907              1.377320   \n",
       "std       1.383222e+05               18164.316990              2.023826   \n",
       "min       5.000000e+00                   0.000000              0.000000   \n",
       "...                ...                        ...                   ...   \n",
       "30%       1.186450e+04                1684.500000              0.000000   \n",
       "50%       3.313250e+04                3049.000000              1.000000   \n",
       "99%       6.815846e+05               62413.900000              8.000000   \n",
       "max       1.689764e+06              656730.000000             43.000000   \n",
       "\n",
       "       num_user_for_reviews        budget   title_year  \\\n",
       "count           4895.000000  4.432000e+03  4810.000000   \n",
       "mean             267.668846  3.654749e+07  2002.447609   \n",
       "std              372.934839  1.002427e+08    12.453977   \n",
       "min                1.000000  2.180000e+02  1916.000000   \n",
       "...                     ...           ...          ...   \n",
       "30%               80.000000  8.000000e+06  2000.000000   \n",
       "50%              153.000000  1.985000e+07  2005.000000   \n",
       "99%             1999.240000  2.000000e+08  2016.000000   \n",
       "max             5060.000000  4.200000e+09  2016.000000   \n",
       "\n",
       "       actor_2_facebook_likes   imdb_score  aspect_ratio  movie_facebook_likes  \n",
       "count             4903.000000  4916.000000   4590.000000           4916.000000  \n",
       "mean              1621.923516     6.437429      2.222349           7348.294142  \n",
       "std               4011.299523     1.127802      1.402940          19206.016458  \n",
       "min                  0.000000     1.600000      1.180000              0.000000  \n",
       "...                       ...          ...           ...                   ...  \n",
       "30%                345.000000     6.000000      1.850000              0.000000  \n",
       "50%                593.000000     6.600000      2.350000            159.000000  \n",
       "99%              17000.000000     8.500000      4.000000          93850.000000  \n",
       "max             137000.000000     9.500000     16.000000         349000.000000  \n",
       "\n",
       "[9 rows x 16 columns]"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movie.describe(percentiles=[.01, .3, .99]) # 调整统计的内容，争对百分位数percentiles，只看1%，30%和99%。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "color                      19\n",
       "director_name             102\n",
       "num_critic_for_reviews     49\n",
       "duration                   15\n",
       "                         ... \n",
       "actor_2_facebook_likes     13\n",
       "imdb_score                  0\n",
       "aspect_ratio              326\n",
       "movie_facebook_likes        0\n",
       "Length: 28, dtype: int64"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movie.isnull().sum() # 各列空值元素数量统计，不确定的话可以先输出movie.isnull()的内容看看。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "num_critic_for_reviews     NaN\n",
       "duration                   NaN\n",
       "director_facebook_likes    NaN\n",
       "actor_3_facebook_likes     NaN\n",
       "                          ... \n",
       "actor_2_facebook_likes     NaN\n",
       "imdb_score                 1.6\n",
       "aspect_ratio               NaN\n",
       "movie_facebook_likes         0\n",
       "Length: 19, dtype: object"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movie.min(skipna=False) # 不跳过空值NaN，结果全部是空值。默认skipna=True"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## DataFrame方法的链式调用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>color</th>\n",
       "      <th>director_name</th>\n",
       "      <th>num_critic_for_reviews</th>\n",
       "      <th>duration</th>\n",
       "      <th>director_facebook_likes</th>\n",
       "      <th>actor_3_facebook_likes</th>\n",
       "      <th>actor_2_name</th>\n",
       "      <th>actor_1_facebook_likes</th>\n",
       "      <th>gross</th>\n",
       "      <th>genres</th>\n",
       "      <th>actor_1_name</th>\n",
       "      <th>movie_title</th>\n",
       "      <th>num_voted_users</th>\n",
       "      <th>cast_total_facebook_likes</th>\n",
       "      <th>actor_3_name</th>\n",
       "      <th>facenumber_in_poster</th>\n",
       "      <th>plot_keywords</th>\n",
       "      <th>movie_imdb_link</th>\n",
       "      <th>num_user_for_reviews</th>\n",
       "      <th>language</th>\n",
       "      <th>country</th>\n",
       "      <th>content_rating</th>\n",
       "      <th>budget</th>\n",
       "      <th>title_year</th>\n",
       "      <th>actor_2_facebook_likes</th>\n",
       "      <th>imdb_score</th>\n",
       "      <th>aspect_ratio</th>\n",
       "      <th>movie_facebook_likes</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   color  director_name  num_critic_for_reviews  duration  \\\n",
       "0  False          False                   False     False   \n",
       "1  False          False                   False     False   \n",
       "2  False          False                   False     False   \n",
       "3  False          False                   False     False   \n",
       "4   True          False                    True      True   \n",
       "\n",
       "   director_facebook_likes  actor_3_facebook_likes  actor_2_name  \\\n",
       "0                    False                   False         False   \n",
       "1                    False                   False         False   \n",
       "2                    False                   False         False   \n",
       "3                    False                   False         False   \n",
       "4                    False                    True         False   \n",
       "\n",
       "   actor_1_facebook_likes  gross  genres  actor_1_name  movie_title  \\\n",
       "0                   False  False   False         False        False   \n",
       "1                   False  False   False         False        False   \n",
       "2                   False  False   False         False        False   \n",
       "3                   False  False   False         False        False   \n",
       "4                   False   True   False         False        False   \n",
       "\n",
       "   num_voted_users  cast_total_facebook_likes  actor_3_name  \\\n",
       "0            False                      False         False   \n",
       "1            False                      False         False   \n",
       "2            False                      False         False   \n",
       "3            False                      False         False   \n",
       "4            False                      False          True   \n",
       "\n",
       "   facenumber_in_poster  plot_keywords  movie_imdb_link  num_user_for_reviews  \\\n",
       "0                 False          False            False                 False   \n",
       "1                 False          False            False                 False   \n",
       "2                 False          False            False                 False   \n",
       "3                 False          False            False                 False   \n",
       "4                 False           True            False                  True   \n",
       "\n",
       "   language  country  content_rating  budget  title_year  \\\n",
       "0     False    False           False   False       False   \n",
       "1     False    False           False   False       False   \n",
       "2     False    False           False   False       False   \n",
       "3     False    False           False   False       False   \n",
       "4      True     True            True    True        True   \n",
       "\n",
       "   actor_2_facebook_likes  imdb_score  aspect_ratio  movie_facebook_likes  \n",
       "0                   False       False         False                 False  \n",
       "1                   False       False         False                 False  \n",
       "2                   False       False         False                 False  \n",
       "3                   False       False         False                 False  \n",
       "4                   False       False          True                 False  "
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movie = pd.read_csv('data/movie.csv')\n",
    "movie.isnull().head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "color                       19\n",
       "director_name              102\n",
       "num_critic_for_reviews      49\n",
       "duration                    15\n",
       "director_facebook_likes    102\n",
       "dtype: int64"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movie.isnull().sum().head() # 各列空值元素数量统计，只看前几条记录。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2654"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movie.isnull().sum().sum() # 先统计每列有多少空值，然后sum看整个DataFrame有多少空值。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movie.isnull().any().any() # 第一个any返回一个Series，对应的列上有没有空值（有就返回True）。第二个any()检查返回的列中，有没有结果为True的。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "bool    28\n",
       "dtype: int64"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movie.isnull().dtypes.value_counts() # isnull返回的是布尔值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "movie_title                Æon Flux\n",
       "director_facebook_likes       23000\n",
       "dtype: object"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movie[['color', 'movie_title', 'director_facebook_likes']].max() # color是布尔类型，无法找最大值。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "color                                                          Color\n",
       "director_name                                          Étienne Faure\n",
       "actor_2_name                                           Zubaida Sahar\n",
       "genres                                                       Western\n",
       "                                         ...                        \n",
       "movie_imdb_link    http://www.imdb.com/title/tt5574490/?ref_=fn_t...\n",
       "language                                                        Zulu\n",
       "country                                                 West Germany\n",
       "content_rating                                                     X\n",
       "Length: 12, dtype: object"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "movie.select_dtypes(['object']).fillna('').max() # 对于object类型，空值填充字符串，然后返回最大值。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## DataFrame的操作符"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>INSTNM</th>\n",
       "      <th>CITY</th>\n",
       "      <th>STABBR</th>\n",
       "      <th>HBCU</th>\n",
       "      <th>MENONLY</th>\n",
       "      <th>WOMENONLY</th>\n",
       "      <th>RELAFFIL</th>\n",
       "      <th>SATVRMID</th>\n",
       "      <th>SATMTMID</th>\n",
       "      <th>DISTANCEONLY</th>\n",
       "      <th>UGDS</th>\n",
       "      <th>UGDS_WHITE</th>\n",
       "      <th>UGDS_BLACK</th>\n",
       "      <th>UGDS_HISP</th>\n",
       "      <th>UGDS_ASIAN</th>\n",
       "      <th>UGDS_AIAN</th>\n",
       "      <th>UGDS_NHPI</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "      <th>PPTUG_EF</th>\n",
       "      <th>CURROPER</th>\n",
       "      <th>PCTPELL</th>\n",
       "      <th>PCTFLOAN</th>\n",
       "      <th>UG25ABV</th>\n",
       "      <th>MD_EARN_WNE_P10</th>\n",
       "      <th>GRAD_DEBT_MDN_SUPP</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Alabama A &amp; M University</td>\n",
       "      <td>Normal</td>\n",
       "      <td>AL</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>424.0</td>\n",
       "      <td>420.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>4206.0</td>\n",
       "      <td>0.0333</td>\n",
       "      <td>0.9353</td>\n",
       "      <td>0.0055</td>\n",
       "      <td>0.0019</td>\n",
       "      <td>0.0024</td>\n",
       "      <td>0.0019</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0059</td>\n",
       "      <td>0.0138</td>\n",
       "      <td>0.0656</td>\n",
       "      <td>1</td>\n",
       "      <td>0.7356</td>\n",
       "      <td>0.8284</td>\n",
       "      <td>0.1049</td>\n",
       "      <td>30300</td>\n",
       "      <td>33888</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>University of Alabama at Birmingham</td>\n",
       "      <td>Birmingham</td>\n",
       "      <td>AL</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>570.0</td>\n",
       "      <td>565.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>11383.0</td>\n",
       "      <td>0.5922</td>\n",
       "      <td>0.2600</td>\n",
       "      <td>0.0283</td>\n",
       "      <td>0.0518</td>\n",
       "      <td>0.0022</td>\n",
       "      <td>0.0007</td>\n",
       "      <td>0.0368</td>\n",
       "      <td>0.0179</td>\n",
       "      <td>0.0100</td>\n",
       "      <td>0.2607</td>\n",
       "      <td>1</td>\n",
       "      <td>0.3460</td>\n",
       "      <td>0.5214</td>\n",
       "      <td>0.2422</td>\n",
       "      <td>39700</td>\n",
       "      <td>21941.5</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Amridge University</td>\n",
       "      <td>Montgomery</td>\n",
       "      <td>AL</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1.0</td>\n",
       "      <td>291.0</td>\n",
       "      <td>0.2990</td>\n",
       "      <td>0.4192</td>\n",
       "      <td>0.0069</td>\n",
       "      <td>0.0034</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.2715</td>\n",
       "      <td>0.4536</td>\n",
       "      <td>1</td>\n",
       "      <td>0.6801</td>\n",
       "      <td>0.7795</td>\n",
       "      <td>0.8540</td>\n",
       "      <td>40100</td>\n",
       "      <td>23370</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>University of Alabama in Huntsville</td>\n",
       "      <td>Huntsville</td>\n",
       "      <td>AL</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>595.0</td>\n",
       "      <td>590.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>5451.0</td>\n",
       "      <td>0.6988</td>\n",
       "      <td>0.1255</td>\n",
       "      <td>0.0382</td>\n",
       "      <td>0.0376</td>\n",
       "      <td>0.0143</td>\n",
       "      <td>0.0002</td>\n",
       "      <td>0.0172</td>\n",
       "      <td>0.0332</td>\n",
       "      <td>0.0350</td>\n",
       "      <td>0.2146</td>\n",
       "      <td>1</td>\n",
       "      <td>0.3072</td>\n",
       "      <td>0.4596</td>\n",
       "      <td>0.2640</td>\n",
       "      <td>45500</td>\n",
       "      <td>24097</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Alabama State University</td>\n",
       "      <td>Montgomery</td>\n",
       "      <td>AL</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0</td>\n",
       "      <td>425.0</td>\n",
       "      <td>430.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>4811.0</td>\n",
       "      <td>0.0158</td>\n",
       "      <td>0.9208</td>\n",
       "      <td>0.0121</td>\n",
       "      <td>0.0019</td>\n",
       "      <td>0.0010</td>\n",
       "      <td>0.0006</td>\n",
       "      <td>0.0098</td>\n",
       "      <td>0.0243</td>\n",
       "      <td>0.0137</td>\n",
       "      <td>0.0892</td>\n",
       "      <td>1</td>\n",
       "      <td>0.7347</td>\n",
       "      <td>0.7554</td>\n",
       "      <td>0.1270</td>\n",
       "      <td>26600</td>\n",
       "      <td>33118.5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                INSTNM        CITY STABBR  HBCU  MENONLY  \\\n",
       "0             Alabama A & M University      Normal     AL   1.0      0.0   \n",
       "1  University of Alabama at Birmingham  Birmingham     AL   0.0      0.0   \n",
       "2                   Amridge University  Montgomery     AL   0.0      0.0   \n",
       "3  University of Alabama in Huntsville  Huntsville     AL   0.0      0.0   \n",
       "4             Alabama State University  Montgomery     AL   1.0      0.0   \n",
       "\n",
       "   WOMENONLY  RELAFFIL  SATVRMID  SATMTMID  DISTANCEONLY     UGDS  UGDS_WHITE  \\\n",
       "0        0.0         0     424.0     420.0           0.0   4206.0      0.0333   \n",
       "1        0.0         0     570.0     565.0           0.0  11383.0      0.5922   \n",
       "2        0.0         1       NaN       NaN           1.0    291.0      0.2990   \n",
       "3        0.0         0     595.0     590.0           0.0   5451.0      0.6988   \n",
       "4        0.0         0     425.0     430.0           0.0   4811.0      0.0158   \n",
       "\n",
       "   UGDS_BLACK  UGDS_HISP  UGDS_ASIAN  UGDS_AIAN  UGDS_NHPI  UGDS_2MOR  \\\n",
       "0      0.9353     0.0055      0.0019     0.0024     0.0019     0.0000   \n",
       "1      0.2600     0.0283      0.0518     0.0022     0.0007     0.0368   \n",
       "2      0.4192     0.0069      0.0034     0.0000     0.0000     0.0000   \n",
       "3      0.1255     0.0382      0.0376     0.0143     0.0002     0.0172   \n",
       "4      0.9208     0.0121      0.0019     0.0010     0.0006     0.0098   \n",
       "\n",
       "   UGDS_NRA  UGDS_UNKN  PPTUG_EF  CURROPER  PCTPELL  PCTFLOAN  UG25ABV  \\\n",
       "0    0.0059     0.0138    0.0656         1   0.7356    0.8284   0.1049   \n",
       "1    0.0179     0.0100    0.2607         1   0.3460    0.5214   0.2422   \n",
       "2    0.0000     0.2715    0.4536         1   0.6801    0.7795   0.8540   \n",
       "3    0.0332     0.0350    0.2146         1   0.3072    0.4596   0.2640   \n",
       "4    0.0243     0.0137    0.0892         1   0.7347    0.7554   0.1270   \n",
       "\n",
       "  MD_EARN_WNE_P10 GRAD_DEBT_MDN_SUPP  \n",
       "0           30300              33888  \n",
       "1           39700            21941.5  \n",
       "2           40100              23370  \n",
       "3           45500              24097  \n",
       "4           26600            33118.5  "
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college = pd.read_csv('data/college.csv')\n",
    "college.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "ename": "TypeError",
     "evalue": "can only concatenate str (not \"int\") to str",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32mc:\\users\\lin\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\pandas\\core\\ops\\array_ops.py\u001b[0m in \u001b[0;36mna_arithmetic_op\u001b[1;34m(left, right, op, str_rep)\u001b[0m\n\u001b[0;32m    148\u001b[0m     \u001b[1;32mtry\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 149\u001b[1;33m         \u001b[0mresult\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mexpressions\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mevaluate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mop\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mstr_rep\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mleft\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mright\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    150\u001b[0m     \u001b[1;32mexcept\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\users\\lin\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\pandas\\core\\computation\\expressions.py\u001b[0m in \u001b[0;36mevaluate\u001b[1;34m(op, op_str, a, b, use_numexpr)\u001b[0m\n\u001b[0;32m    207\u001b[0m     \u001b[1;32mif\u001b[0m \u001b[0muse_numexpr\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 208\u001b[1;33m         \u001b[1;32mreturn\u001b[0m \u001b[0m_evaluate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mop\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mop_str\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0ma\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mb\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    209\u001b[0m     \u001b[1;32mreturn\u001b[0m \u001b[0m_evaluate_standard\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mop\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mop_str\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0ma\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mb\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\users\\lin\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\pandas\\core\\computation\\expressions.py\u001b[0m in \u001b[0;36m_evaluate_standard\u001b[1;34m(op, op_str, a, b)\u001b[0m\n\u001b[0;32m     69\u001b[0m     \u001b[1;32mwith\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0merrstate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mall\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m\"ignore\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m---> 70\u001b[1;33m         \u001b[1;32mreturn\u001b[0m \u001b[0mop\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0ma\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mb\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m     71\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mTypeError\u001b[0m: can only concatenate str (not \"int\") to str",
      "\nDuring handling of the above exception, another exception occurred:\n",
      "\u001b[1;31mTypeError\u001b[0m                                 Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-37-1dc17df13b98>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[1;32m----> 1\u001b[1;33m \u001b[0mcollege\u001b[0m \u001b[1;33m+\u001b[0m \u001b[1;36m5\u001b[0m \u001b[1;31m# 错误，因为有非数值类型。\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;32mc:\\users\\lin\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\pandas\\core\\ops\\__init__.py\u001b[0m in \u001b[0;36mf\u001b[1;34m(self, other, axis, level, fill_value)\u001b[0m\n\u001b[0;32m    781\u001b[0m                 \u001b[0mself\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mfillna\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfill_value\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    782\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 783\u001b[1;33m             \u001b[0mnew_data\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mdispatch_to_series\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mother\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mop\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mstr_rep\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    784\u001b[0m             \u001b[1;32mreturn\u001b[0m \u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_construct_result\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mnew_data\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    785\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\users\\lin\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\pandas\\core\\ops\\__init__.py\u001b[0m in \u001b[0;36mdispatch_to_series\u001b[1;34m(left, right, func, str_rep, axis)\u001b[0m\n\u001b[0;32m    379\u001b[0m         \u001b[1;31m# Get the appropriate array-op to apply to each block's values.\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    380\u001b[0m         \u001b[0marray_op\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mget_array_op\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mfunc\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mstr_rep\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mstr_rep\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 381\u001b[1;33m         \u001b[0mbm\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mleft\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_data\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mapply\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0marray_op\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mright\u001b[0m\u001b[1;33m=\u001b[0m\u001b[0mright\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    382\u001b[0m         \u001b[1;32mreturn\u001b[0m \u001b[0mtype\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mleft\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mbm\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    383\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\users\\lin\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\pandas\\core\\internals\\managers.py\u001b[0m in \u001b[0;36mapply\u001b[1;34m(self, f, filter, **kwargs)\u001b[0m\n\u001b[0;32m    438\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    439\u001b[0m             \u001b[1;32mif\u001b[0m \u001b[0mcallable\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mf\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 440\u001b[1;33m                 \u001b[0mapplied\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mb\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mapply\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mf\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    441\u001b[0m             \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    442\u001b[0m                 \u001b[0mapplied\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mgetattr\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mb\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mf\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\users\\lin\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\pandas\\core\\internals\\blocks.py\u001b[0m in \u001b[0;36mapply\u001b[1;34m(self, func, **kwargs)\u001b[0m\n\u001b[0;32m    388\u001b[0m         \"\"\"\n\u001b[0;32m    389\u001b[0m         \u001b[1;32mwith\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0merrstate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mall\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m\"ignore\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 390\u001b[1;33m             \u001b[0mresult\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mfunc\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mself\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mvalues\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m**\u001b[0m\u001b[0mkwargs\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    391\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    392\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[0mis_extension_array_dtype\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mresult\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;32mand\u001b[0m \u001b[0mresult\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mndim\u001b[0m \u001b[1;33m>\u001b[0m \u001b[1;36m1\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\users\\lin\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\pandas\\core\\ops\\array_ops.py\u001b[0m in \u001b[0;36marithmetic_op\u001b[1;34m(left, right, op, str_rep)\u001b[0m\n\u001b[0;32m    195\u001b[0m     \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    196\u001b[0m         \u001b[1;32mwith\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0merrstate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mall\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m\"ignore\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 197\u001b[1;33m             \u001b[0mres_values\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mna_arithmetic_op\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mlvalues\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mrvalues\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mop\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mstr_rep\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    198\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    199\u001b[0m     \u001b[1;32mreturn\u001b[0m \u001b[0mres_values\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\users\\lin\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\pandas\\core\\ops\\array_ops.py\u001b[0m in \u001b[0;36mna_arithmetic_op\u001b[1;34m(left, right, op, str_rep)\u001b[0m\n\u001b[0;32m    149\u001b[0m         \u001b[0mresult\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mexpressions\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mevaluate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mop\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mstr_rep\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mleft\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mright\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    150\u001b[0m     \u001b[1;32mexcept\u001b[0m \u001b[0mTypeError\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 151\u001b[1;33m         \u001b[0mresult\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mmasked_arith_op\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mleft\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mright\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mop\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    152\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    153\u001b[0m     \u001b[1;32mreturn\u001b[0m \u001b[0mmissing\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mdispatch_fill_zeros\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mop\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mleft\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mright\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mresult\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\users\\lin\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\pandas\\core\\ops\\array_ops.py\u001b[0m in \u001b[0;36mmasked_arith_op\u001b[1;34m(x, y, op)\u001b[0m\n\u001b[0;32m    110\u001b[0m         \u001b[1;32mif\u001b[0m \u001b[0mmask\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0many\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    111\u001b[0m             \u001b[1;32mwith\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0merrstate\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mall\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;34m\"ignore\"\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 112\u001b[1;33m                 \u001b[0mresult\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mmask\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mop\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mxrav\u001b[0m\u001b[1;33m[\u001b[0m\u001b[0mmask\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0my\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    113\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    114\u001b[0m     \u001b[0mresult\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0m_\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mmaybe_upcast_putmask\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mresult\u001b[0m\u001b[1;33m,\u001b[0m \u001b[1;33m~\u001b[0m\u001b[0mmask\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mnp\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mnan\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mTypeError\u001b[0m: can only concatenate str (not \"int\") to str"
     ]
    }
   ],
   "source": [
    "college + 5 # 错误，因为有非数值类型。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "c:\\users\\lin\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\pandas\\core\\ops\\array_ops.py:253: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison\n",
      "  res_values = method(rvalues)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>INSTNM</th>\n",
       "      <th>CITY</th>\n",
       "      <th>STABBR</th>\n",
       "      <th>HBCU</th>\n",
       "      <th>MENONLY</th>\n",
       "      <th>WOMENONLY</th>\n",
       "      <th>RELAFFIL</th>\n",
       "      <th>SATVRMID</th>\n",
       "      <th>SATMTMID</th>\n",
       "      <th>DISTANCEONLY</th>\n",
       "      <th>UGDS</th>\n",
       "      <th>UGDS_WHITE</th>\n",
       "      <th>UGDS_BLACK</th>\n",
       "      <th>UGDS_HISP</th>\n",
       "      <th>UGDS_ASIAN</th>\n",
       "      <th>UGDS_AIAN</th>\n",
       "      <th>UGDS_NHPI</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "      <th>PPTUG_EF</th>\n",
       "      <th>CURROPER</th>\n",
       "      <th>PCTPELL</th>\n",
       "      <th>PCTFLOAN</th>\n",
       "      <th>UG25ABV</th>\n",
       "      <th>MD_EARN_WNE_P10</th>\n",
       "      <th>GRAD_DEBT_MDN_SUPP</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7531</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7532</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7533</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7534</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>7535 rows × 27 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "      INSTNM   CITY  STABBR   HBCU  MENONLY  WOMENONLY  RELAFFIL  SATVRMID  \\\n",
       "0      False  False   False  False    False      False     False     False   \n",
       "1      False  False   False  False    False      False     False     False   \n",
       "2      False  False   False  False    False      False     False     False   \n",
       "3      False  False   False  False    False      False     False     False   \n",
       "...      ...    ...     ...    ...      ...        ...       ...       ...   \n",
       "7531   False  False   False  False    False      False     False     False   \n",
       "7532   False  False   False  False    False      False     False     False   \n",
       "7533   False  False   False  False    False      False     False     False   \n",
       "7534   False  False   False  False    False      False     False     False   \n",
       "\n",
       "      SATMTMID  DISTANCEONLY   UGDS  UGDS_WHITE  UGDS_BLACK  UGDS_HISP  \\\n",
       "0        False         False  False       False       False      False   \n",
       "1        False         False  False       False       False      False   \n",
       "2        False         False  False       False       False      False   \n",
       "3        False         False  False       False       False      False   \n",
       "...        ...           ...    ...         ...         ...        ...   \n",
       "7531     False         False  False       False       False      False   \n",
       "7532     False         False  False       False       False      False   \n",
       "7533     False         False  False       False       False      False   \n",
       "7534     False         False  False       False       False      False   \n",
       "\n",
       "      UGDS_ASIAN  UGDS_AIAN  UGDS_NHPI  UGDS_2MOR  UGDS_NRA  UGDS_UNKN  \\\n",
       "0          False      False      False      False     False      False   \n",
       "1          False      False      False      False     False      False   \n",
       "2          False      False      False      False     False      False   \n",
       "3          False      False      False      False     False      False   \n",
       "...          ...        ...        ...        ...       ...        ...   \n",
       "7531       False      False      False      False     False      False   \n",
       "7532       False      False      False      False     False      False   \n",
       "7533       False      False      False      False     False      False   \n",
       "7534       False      False      False      False     False      False   \n",
       "\n",
       "      PPTUG_EF  CURROPER  PCTPELL  PCTFLOAN  UG25ABV  MD_EARN_WNE_P10  \\\n",
       "0        False     False    False     False    False            False   \n",
       "1        False     False    False     False    False            False   \n",
       "2        False     False    False     False    False            False   \n",
       "3        False     False    False     False    False            False   \n",
       "...        ...       ...      ...       ...      ...              ...   \n",
       "7531     False     False    False     False    False            False   \n",
       "7532     False     False    False     False    False            False   \n",
       "7533     False     False    False     False    False            False   \n",
       "7534     False     False    False     False    False            False   \n",
       "\n",
       "      GRAD_DEBT_MDN_SUPP  \n",
       "0                  False  \n",
       "1                  False  \n",
       "2                  False  \n",
       "3                  False  \n",
       "...                  ...  \n",
       "7531               False  \n",
       "7532               False  \n",
       "7533               False  \n",
       "7534               False  \n",
       "\n",
       "[7535 rows x 27 columns]"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college == 'asdf' # 每个元素与'asdf'比较，老版本可能会报错。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>UGDS_WHITE</th>\n",
       "      <th>UGDS_BLACK</th>\n",
       "      <th>UGDS_HISP</th>\n",
       "      <th>UGDS_ASIAN</th>\n",
       "      <th>UGDS_AIAN</th>\n",
       "      <th>UGDS_NHPI</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Alabama A &amp; M University</th>\n",
       "      <td>0.0333</td>\n",
       "      <td>0.9353</td>\n",
       "      <td>0.0055</td>\n",
       "      <td>0.0019</td>\n",
       "      <td>0.0024</td>\n",
       "      <td>0.0019</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0059</td>\n",
       "      <td>0.0138</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama at Birmingham</th>\n",
       "      <td>0.5922</td>\n",
       "      <td>0.2600</td>\n",
       "      <td>0.0283</td>\n",
       "      <td>0.0518</td>\n",
       "      <td>0.0022</td>\n",
       "      <td>0.0007</td>\n",
       "      <td>0.0368</td>\n",
       "      <td>0.0179</td>\n",
       "      <td>0.0100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Amridge University</th>\n",
       "      <td>0.2990</td>\n",
       "      <td>0.4192</td>\n",
       "      <td>0.0069</td>\n",
       "      <td>0.0034</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.2715</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama in Huntsville</th>\n",
       "      <td>0.6988</td>\n",
       "      <td>0.1255</td>\n",
       "      <td>0.0382</td>\n",
       "      <td>0.0376</td>\n",
       "      <td>0.0143</td>\n",
       "      <td>0.0002</td>\n",
       "      <td>0.0172</td>\n",
       "      <td>0.0332</td>\n",
       "      <td>0.0350</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Alabama State University</th>\n",
       "      <td>0.0158</td>\n",
       "      <td>0.9208</td>\n",
       "      <td>0.0121</td>\n",
       "      <td>0.0019</td>\n",
       "      <td>0.0010</td>\n",
       "      <td>0.0006</td>\n",
       "      <td>0.0098</td>\n",
       "      <td>0.0243</td>\n",
       "      <td>0.0137</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                     UGDS_WHITE  UGDS_BLACK  UGDS_HISP  \\\n",
       "INSTNM                                                                   \n",
       "Alabama A & M University                 0.0333      0.9353     0.0055   \n",
       "University of Alabama at Birmingham      0.5922      0.2600     0.0283   \n",
       "Amridge University                       0.2990      0.4192     0.0069   \n",
       "University of Alabama in Huntsville      0.6988      0.1255     0.0382   \n",
       "Alabama State University                 0.0158      0.9208     0.0121   \n",
       "\n",
       "                                     UGDS_ASIAN  UGDS_AIAN  UGDS_NHPI  \\\n",
       "INSTNM                                                                  \n",
       "Alabama A & M University                 0.0019     0.0024     0.0019   \n",
       "University of Alabama at Birmingham      0.0518     0.0022     0.0007   \n",
       "Amridge University                       0.0034     0.0000     0.0000   \n",
       "University of Alabama in Huntsville      0.0376     0.0143     0.0002   \n",
       "Alabama State University                 0.0019     0.0010     0.0006   \n",
       "\n",
       "                                     UGDS_2MOR  UGDS_NRA  UGDS_UNKN  \n",
       "INSTNM                                                               \n",
       "Alabama A & M University                0.0000    0.0059     0.0138  \n",
       "University of Alabama at Birmingham     0.0368    0.0179     0.0100  \n",
       "Amridge University                      0.0000    0.0000     0.2715  \n",
       "University of Alabama in Huntsville     0.0172    0.0332     0.0350  \n",
       "Alabama State University                0.0098    0.0243     0.0137  "
      ]
     },
     "execution_count": 39,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college = pd.read_csv('data/college.csv', index_col='INSTNM')\n",
    "college_ugds_ = college.filter(like='UGDS_')\n",
    "college_ugds_.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>UGDS_WHITE</th>\n",
       "      <th>UGDS_BLACK</th>\n",
       "      <th>UGDS_HISP</th>\n",
       "      <th>UGDS_ASIAN</th>\n",
       "      <th>UGDS_AIAN</th>\n",
       "      <th>UGDS_NHPI</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Alabama A &amp; M University</th>\n",
       "      <td>0.03831</td>\n",
       "      <td>0.94031</td>\n",
       "      <td>0.01051</td>\n",
       "      <td>0.00691</td>\n",
       "      <td>0.00741</td>\n",
       "      <td>0.00691</td>\n",
       "      <td>0.00501</td>\n",
       "      <td>0.01091</td>\n",
       "      <td>0.01881</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama at Birmingham</th>\n",
       "      <td>0.59721</td>\n",
       "      <td>0.26501</td>\n",
       "      <td>0.03331</td>\n",
       "      <td>0.05681</td>\n",
       "      <td>0.00721</td>\n",
       "      <td>0.00571</td>\n",
       "      <td>0.04181</td>\n",
       "      <td>0.02291</td>\n",
       "      <td>0.01501</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Amridge University</th>\n",
       "      <td>0.30401</td>\n",
       "      <td>0.42421</td>\n",
       "      <td>0.01191</td>\n",
       "      <td>0.00841</td>\n",
       "      <td>0.00501</td>\n",
       "      <td>0.00501</td>\n",
       "      <td>0.00501</td>\n",
       "      <td>0.00501</td>\n",
       "      <td>0.27651</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama in Huntsville</th>\n",
       "      <td>0.70381</td>\n",
       "      <td>0.13051</td>\n",
       "      <td>0.04321</td>\n",
       "      <td>0.04261</td>\n",
       "      <td>0.01931</td>\n",
       "      <td>0.00521</td>\n",
       "      <td>0.02221</td>\n",
       "      <td>0.03821</td>\n",
       "      <td>0.04001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Alabama State University</th>\n",
       "      <td>0.02081</td>\n",
       "      <td>0.92581</td>\n",
       "      <td>0.01711</td>\n",
       "      <td>0.00691</td>\n",
       "      <td>0.00601</td>\n",
       "      <td>0.00561</td>\n",
       "      <td>0.01481</td>\n",
       "      <td>0.02931</td>\n",
       "      <td>0.01871</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                     UGDS_WHITE  UGDS_BLACK  UGDS_HISP  \\\n",
       "INSTNM                                                                   \n",
       "Alabama A & M University                0.03831     0.94031    0.01051   \n",
       "University of Alabama at Birmingham     0.59721     0.26501    0.03331   \n",
       "Amridge University                      0.30401     0.42421    0.01191   \n",
       "University of Alabama in Huntsville     0.70381     0.13051    0.04321   \n",
       "Alabama State University                0.02081     0.92581    0.01711   \n",
       "\n",
       "                                     UGDS_ASIAN  UGDS_AIAN  UGDS_NHPI  \\\n",
       "INSTNM                                                                  \n",
       "Alabama A & M University                0.00691    0.00741    0.00691   \n",
       "University of Alabama at Birmingham     0.05681    0.00721    0.00571   \n",
       "Amridge University                      0.00841    0.00501    0.00501   \n",
       "University of Alabama in Huntsville     0.04261    0.01931    0.00521   \n",
       "Alabama State University                0.00691    0.00601    0.00561   \n",
       "\n",
       "                                     UGDS_2MOR  UGDS_NRA  UGDS_UNKN  \n",
       "INSTNM                                                               \n",
       "Alabama A & M University               0.00501   0.01091    0.01881  \n",
       "University of Alabama at Birmingham    0.04181   0.02291    0.01501  \n",
       "Amridge University                     0.00501   0.00501    0.27651  \n",
       "University of Alabama in Huntsville    0.02221   0.03821    0.04001  \n",
       "Alabama State University               0.01481   0.02931    0.01871  "
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college_ugds_.head() + .00501 # 成功，因为都是数值列。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>UGDS_WHITE</th>\n",
       "      <th>UGDS_BLACK</th>\n",
       "      <th>UGDS_HISP</th>\n",
       "      <th>UGDS_ASIAN</th>\n",
       "      <th>UGDS_AIAN</th>\n",
       "      <th>UGDS_NHPI</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Alabama A &amp; M University</th>\n",
       "      <td>3.0</td>\n",
       "      <td>94.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama at Birmingham</th>\n",
       "      <td>59.0</td>\n",
       "      <td>26.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>5.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Amridge University</th>\n",
       "      <td>30.0</td>\n",
       "      <td>42.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>27.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama in Huntsville</th>\n",
       "      <td>70.0</td>\n",
       "      <td>13.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>4.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>3.0</td>\n",
       "      <td>4.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Alabama State University</th>\n",
       "      <td>2.0</td>\n",
       "      <td>92.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>1.0</td>\n",
       "      <td>2.0</td>\n",
       "      <td>1.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                     UGDS_WHITE  UGDS_BLACK  UGDS_HISP  \\\n",
       "INSTNM                                                                   \n",
       "Alabama A & M University                    3.0        94.0        1.0   \n",
       "University of Alabama at Birmingham        59.0        26.0        3.0   \n",
       "Amridge University                         30.0        42.0        1.0   \n",
       "University of Alabama in Huntsville        70.0        13.0        4.0   \n",
       "Alabama State University                    2.0        92.0        1.0   \n",
       "\n",
       "                                     UGDS_ASIAN  UGDS_AIAN  UGDS_NHPI  \\\n",
       "INSTNM                                                                  \n",
       "Alabama A & M University                    0.0        0.0        0.0   \n",
       "University of Alabama at Birmingham         5.0        0.0        0.0   \n",
       "Amridge University                          0.0        0.0        0.0   \n",
       "University of Alabama in Huntsville         4.0        1.0        0.0   \n",
       "Alabama State University                    0.0        0.0        0.0   \n",
       "\n",
       "                                     UGDS_2MOR  UGDS_NRA  UGDS_UNKN  \n",
       "INSTNM                                                               \n",
       "Alabama A & M University                   0.0       1.0        1.0  \n",
       "University of Alabama at Birmingham        4.0       2.0        1.0  \n",
       "Amridge University                         0.0       0.0       27.0  \n",
       "University of Alabama in Huntsville        2.0       3.0        4.0  \n",
       "Alabama State University                   1.0       2.0        1.0  "
      ]
     },
     "execution_count": 41,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(college_ugds_.head() + .00501) // .01 # 每个元素除0.01，然后去掉小数点后面部分取整。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>UGDS_WHITE</th>\n",
       "      <th>UGDS_BLACK</th>\n",
       "      <th>UGDS_HISP</th>\n",
       "      <th>UGDS_ASIAN</th>\n",
       "      <th>UGDS_AIAN</th>\n",
       "      <th>UGDS_NHPI</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Alabama A &amp; M University</th>\n",
       "      <td>0.03</td>\n",
       "      <td>0.94</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama at Birmingham</th>\n",
       "      <td>0.59</td>\n",
       "      <td>0.26</td>\n",
       "      <td>0.03</td>\n",
       "      <td>0.05</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.04</td>\n",
       "      <td>0.02</td>\n",
       "      <td>0.01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Amridge University</th>\n",
       "      <td>0.30</td>\n",
       "      <td>0.42</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama in Huntsville</th>\n",
       "      <td>0.70</td>\n",
       "      <td>0.13</td>\n",
       "      <td>0.04</td>\n",
       "      <td>0.04</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.02</td>\n",
       "      <td>0.03</td>\n",
       "      <td>0.04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Alabama State University</th>\n",
       "      <td>0.02</td>\n",
       "      <td>0.92</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.02</td>\n",
       "      <td>0.01</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                     UGDS_WHITE  UGDS_BLACK  UGDS_HISP  \\\n",
       "INSTNM                                                                   \n",
       "Alabama A & M University                   0.03        0.94       0.01   \n",
       "University of Alabama at Birmingham        0.59        0.26       0.03   \n",
       "Amridge University                         0.30        0.42       0.01   \n",
       "University of Alabama in Huntsville        0.70        0.13       0.04   \n",
       "Alabama State University                   0.02        0.92       0.01   \n",
       "\n",
       "                                     UGDS_ASIAN  UGDS_AIAN  UGDS_NHPI  \\\n",
       "INSTNM                                                                  \n",
       "Alabama A & M University                   0.00       0.00        0.0   \n",
       "University of Alabama at Birmingham        0.05       0.00        0.0   \n",
       "Amridge University                         0.00       0.00        0.0   \n",
       "University of Alabama in Huntsville        0.04       0.01        0.0   \n",
       "Alabama State University                   0.00       0.00        0.0   \n",
       "\n",
       "                                     UGDS_2MOR  UGDS_NRA  UGDS_UNKN  \n",
       "INSTNM                                                               \n",
       "Alabama A & M University                  0.00      0.01       0.01  \n",
       "University of Alabama at Birmingham       0.04      0.02       0.01  \n",
       "Amridge University                        0.00      0.00       0.27  \n",
       "University of Alabama in Huntsville       0.02      0.03       0.04  \n",
       "Alabama State University                  0.01      0.02       0.01  "
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college_ugds_op_round = (college_ugds_ + .00501) // .01 / 100 # 上面的结果除100，Python3开始除法自动转为浮点数。\n",
    "college_ugds_op_round.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>UGDS_WHITE</th>\n",
       "      <th>UGDS_BLACK</th>\n",
       "      <th>UGDS_HISP</th>\n",
       "      <th>UGDS_ASIAN</th>\n",
       "      <th>UGDS_AIAN</th>\n",
       "      <th>UGDS_NHPI</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Alabama A &amp; M University</th>\n",
       "      <td>0.03</td>\n",
       "      <td>0.94</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama at Birmingham</th>\n",
       "      <td>0.59</td>\n",
       "      <td>0.26</td>\n",
       "      <td>0.03</td>\n",
       "      <td>0.05</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.04</td>\n",
       "      <td>0.02</td>\n",
       "      <td>0.01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Amridge University</th>\n",
       "      <td>0.30</td>\n",
       "      <td>0.42</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama in Huntsville</th>\n",
       "      <td>0.70</td>\n",
       "      <td>0.13</td>\n",
       "      <td>0.04</td>\n",
       "      <td>0.04</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.02</td>\n",
       "      <td>0.03</td>\n",
       "      <td>0.04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Alabama State University</th>\n",
       "      <td>0.02</td>\n",
       "      <td>0.92</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.02</td>\n",
       "      <td>0.01</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                     UGDS_WHITE  UGDS_BLACK  UGDS_HISP  \\\n",
       "INSTNM                                                                   \n",
       "Alabama A & M University                   0.03        0.94       0.01   \n",
       "University of Alabama at Birmingham        0.59        0.26       0.03   \n",
       "Amridge University                         0.30        0.42       0.01   \n",
       "University of Alabama in Huntsville        0.70        0.13       0.04   \n",
       "Alabama State University                   0.02        0.92       0.01   \n",
       "\n",
       "                                     UGDS_ASIAN  UGDS_AIAN  UGDS_NHPI  \\\n",
       "INSTNM                                                                  \n",
       "Alabama A & M University                   0.00       0.00        0.0   \n",
       "University of Alabama at Birmingham        0.05       0.00        0.0   \n",
       "Amridge University                         0.00       0.00        0.0   \n",
       "University of Alabama in Huntsville        0.04       0.01        0.0   \n",
       "Alabama State University                   0.00       0.00        0.0   \n",
       "\n",
       "                                     UGDS_2MOR  UGDS_NRA  UGDS_UNKN  \n",
       "INSTNM                                                               \n",
       "Alabama A & M University                  0.00      0.01       0.01  \n",
       "University of Alabama at Birmingham       0.04      0.02       0.01  \n",
       "Amridge University                        0.00      0.00       0.27  \n",
       "University of Alabama in Huntsville       0.02      0.03       0.04  \n",
       "Alabama State University                  0.01      0.02       0.01  "
      ]
     },
     "execution_count": 43,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college_ugds_round = (college_ugds_ + .00001).round(2) # 保留2位有效数字\n",
    "college_ugds_round.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0.049999999999999996"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    ".045 + .005 # 小心浮点数计算，会莫名其妙多点东西出来！"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>UGDS_WHITE</th>\n",
       "      <th>UGDS_BLACK</th>\n",
       "      <th>UGDS_HISP</th>\n",
       "      <th>UGDS_ASIAN</th>\n",
       "      <th>UGDS_AIAN</th>\n",
       "      <th>UGDS_NHPI</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Alabama A &amp; M University</th>\n",
       "      <td>0.03</td>\n",
       "      <td>0.94</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama at Birmingham</th>\n",
       "      <td>0.59</td>\n",
       "      <td>0.26</td>\n",
       "      <td>0.03</td>\n",
       "      <td>0.05</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.04</td>\n",
       "      <td>0.02</td>\n",
       "      <td>0.01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Amridge University</th>\n",
       "      <td>0.30</td>\n",
       "      <td>0.42</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.27</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama in Huntsville</th>\n",
       "      <td>0.70</td>\n",
       "      <td>0.13</td>\n",
       "      <td>0.04</td>\n",
       "      <td>0.04</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.02</td>\n",
       "      <td>0.03</td>\n",
       "      <td>0.04</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Alabama State University</th>\n",
       "      <td>0.02</td>\n",
       "      <td>0.92</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.00</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.01</td>\n",
       "      <td>0.02</td>\n",
       "      <td>0.01</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                     UGDS_WHITE  UGDS_BLACK  UGDS_HISP  \\\n",
       "INSTNM                                                                   \n",
       "Alabama A & M University                   0.03        0.94       0.01   \n",
       "University of Alabama at Birmingham        0.59        0.26       0.03   \n",
       "Amridge University                         0.30        0.42       0.01   \n",
       "University of Alabama in Huntsville        0.70        0.13       0.04   \n",
       "Alabama State University                   0.02        0.92       0.01   \n",
       "\n",
       "                                     UGDS_ASIAN  UGDS_AIAN  UGDS_NHPI  \\\n",
       "INSTNM                                                                  \n",
       "Alabama A & M University                   0.00       0.00        0.0   \n",
       "University of Alabama at Birmingham        0.05       0.00        0.0   \n",
       "Amridge University                         0.00       0.00        0.0   \n",
       "University of Alabama in Huntsville        0.04       0.01        0.0   \n",
       "Alabama State University                   0.00       0.00        0.0   \n",
       "\n",
       "                                     UGDS_2MOR  UGDS_NRA  UGDS_UNKN  \n",
       "INSTNM                                                               \n",
       "Alabama A & M University                  0.00      0.01       0.01  \n",
       "University of Alabama at Birmingham       0.04      0.02       0.01  \n",
       "Amridge University                        0.00      0.00       0.27  \n",
       "University of Alabama in Huntsville       0.02      0.03       0.04  \n",
       "Alabama State University                  0.01      0.02       0.01  "
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college_ugds_op_round_methods = college_ugds_.add(.00501).floordiv(.01).div(100) # 把操作符转换成对应的方法\n",
    "college_ugds_op_round_methods.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 比较丢失的值（空值）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.nan == np.nan # nan是不能直接比较的，nan = not a number"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 47,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "None == None # None和np.nan不是一回事"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "5 > np.nan # nan不能比大小"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 49,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.nan > 5"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 50,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "5 != np.nan"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [],
   "source": [
    "college = pd.read_csv('data/college.csv', index_col='INSTNM')\n",
    "college_ugds_ = college.filter(like='UGDS_')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>UGDS_WHITE</th>\n",
       "      <th>UGDS_BLACK</th>\n",
       "      <th>UGDS_HISP</th>\n",
       "      <th>UGDS_ASIAN</th>\n",
       "      <th>UGDS_AIAN</th>\n",
       "      <th>UGDS_NHPI</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Alabama A &amp; M University</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama at Birmingham</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Amridge University</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama in Huntsville</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Alabama State University</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                     UGDS_WHITE  UGDS_BLACK  UGDS_HISP  \\\n",
       "INSTNM                                                                   \n",
       "Alabama A & M University                  False       False      False   \n",
       "University of Alabama at Birmingham       False       False      False   \n",
       "Amridge University                        False       False      False   \n",
       "University of Alabama in Huntsville       False       False      False   \n",
       "Alabama State University                  False       False      False   \n",
       "\n",
       "                                     UGDS_ASIAN  UGDS_AIAN  UGDS_NHPI  \\\n",
       "INSTNM                                                                  \n",
       "Alabama A & M University                   True      False       True   \n",
       "University of Alabama at Birmingham       False      False      False   \n",
       "Amridge University                        False      False      False   \n",
       "University of Alabama in Huntsville       False      False      False   \n",
       "Alabama State University                   True      False      False   \n",
       "\n",
       "                                     UGDS_2MOR  UGDS_NRA  UGDS_UNKN  \n",
       "INSTNM                                                               \n",
       "Alabama A & M University                 False     False      False  \n",
       "University of Alabama at Birmingham      False     False      False  \n",
       "Amridge University                       False     False      False  \n",
       "University of Alabama in Huntsville      False     False      False  \n",
       "Alabama State University                 False     False      False  "
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college_ugds_.head() == .0019 # 浮点数比较看运气，注意值为True的单元格。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>UGDS_WHITE</th>\n",
       "      <th>UGDS_BLACK</th>\n",
       "      <th>UGDS_HISP</th>\n",
       "      <th>UGDS_ASIAN</th>\n",
       "      <th>UGDS_AIAN</th>\n",
       "      <th>UGDS_NHPI</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Alabama A &amp; M University</th>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama at Birmingham</th>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Amridge University</th>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama in Huntsville</th>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Alabama State University</th>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                     UGDS_WHITE  UGDS_BLACK  UGDS_HISP  \\\n",
       "INSTNM                                                                   \n",
       "Alabama A & M University                   True        True       True   \n",
       "University of Alabama at Birmingham        True        True       True   \n",
       "Amridge University                         True        True       True   \n",
       "University of Alabama in Huntsville        True        True       True   \n",
       "Alabama State University                   True        True       True   \n",
       "\n",
       "                                     UGDS_ASIAN  UGDS_AIAN  UGDS_NHPI  \\\n",
       "INSTNM                                                                  \n",
       "Alabama A & M University                   True       True       True   \n",
       "University of Alabama at Birmingham        True       True       True   \n",
       "Amridge University                         True       True       True   \n",
       "University of Alabama in Huntsville        True       True       True   \n",
       "Alabama State University                   True       True       True   \n",
       "\n",
       "                                     UGDS_2MOR  UGDS_NRA  UGDS_UNKN  \n",
       "INSTNM                                                               \n",
       "Alabama A & M University                  True      True       True  \n",
       "University of Alabama at Birmingham       True      True       True  \n",
       "Amridge University                        True      True       True  \n",
       "University of Alabama in Huntsville       True      True       True  \n",
       "Alabama State University                  True      True       True  "
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college_self_compare = (college_ugds_ == college_ugds_) # 每个单元格应该都是True，看着是但是实际不是。\n",
    "college_self_compare.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "INSTNM\n",
       "Frank Lloyd Wright School of Architecture                 False\n",
       "Academy of Chinese Culture and Health Sciences            False\n",
       "American Baptist Seminary of the West                     False\n",
       "American Film Institute Conservatory                      False\n",
       "                                                          ...  \n",
       "Rasmussen College - Overland Park                         False\n",
       "National Personal Training Institute of Cleveland         False\n",
       "Bay Area Medical Academy - San Jose Satellite Location    False\n",
       "Excel Learning Center-San Antonio South                   False\n",
       "Name: UGDS_WHITE, Length: 661, dtype: bool"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "ugds_white = college_self_compare['UGDS_WHITE']\n",
    "ugds_white[ugds_white == False] # 这些列的结果就不是True，所以浮点数比较是不靠谱的。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "UGDS_WHITE    False\n",
       "UGDS_BLACK    False\n",
       "UGDS_HISP     False\n",
       "UGDS_ASIAN    False\n",
       "              ...  \n",
       "UGDS_NHPI     False\n",
       "UGDS_2MOR     False\n",
       "UGDS_NRA      False\n",
       "UGDS_UNKN     False\n",
       "Length: 9, dtype: bool"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college_self_compare.all() # 有比较结果为False的列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "UGDS_WHITE    0\n",
       "UGDS_BLACK    0\n",
       "UGDS_HISP     0\n",
       "UGDS_ASIAN    0\n",
       "             ..\n",
       "UGDS_NHPI     0\n",
       "UGDS_2MOR     0\n",
       "UGDS_NRA      0\n",
       "UGDS_UNKN     0\n",
       "Length: 9, dtype: int64"
      ]
     },
     "execution_count": 56,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(college_ugds_ == np.nan).sum() # 因为与空值比较结果一定是False，所以和为0。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "UGDS_WHITE    661\n",
       "UGDS_BLACK    661\n",
       "UGDS_HISP     661\n",
       "UGDS_ASIAN    661\n",
       "             ... \n",
       "UGDS_NHPI     661\n",
       "UGDS_2MOR     661\n",
       "UGDS_NRA      661\n",
       "UGDS_UNKN     661\n",
       "Length: 9, dtype: int64"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college_ugds_.isnull().sum() # 每一列空值的数量"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [],
   "source": [
    "from pandas.testing import assert_frame_equal"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [],
   "source": [
    "assert_frame_equal(college_ugds_, college_ugds_) # 比较DataFrame相等的正确方法"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 60,
   "metadata": {},
   "outputs": [
    {
     "ename": "AssertionError",
     "evalue": "DataFrame.iloc[:, 0] (column name=\"UGDS_WHITE\") are different\n\nDataFrame.iloc[:, 0] (column name=\"UGDS_WHITE\") values are different (0.01327 %)\n[left]:  [0.04, 0.5922, 0.299, 0.6988, 0.0158, 0.7825, 0.7255, 0.7823, 0.5328, 0.8507, 0.7983, 0.4661, 0.028, 0.3046, 0.6408, 0.6979, 0.3874, 0.6921, 0.8957, 0.6273, 0.863, 0.1956, 0.3543, 0.6388, 0.7419, 0.3337, 0.6834, 0.5857, 0.6696, 0.6528, 0.7553, 0.1511, 0.4421, 0.6920000000000001, 0.5727, 0.0169, 0.6479, 0.7266, 0.7912, 0.7123, 0.867, 0.0059, 0.5441, 0.7976, 0.5106, 0.2504, 0.8183, 0.0106, 0.5613, 0.7827, 0.6149, 0.6733, 0.6176, 0.0748, 0.0647, 0.3951, 0.5132, 0.0035, 0.4333, 0.8009, 0.5747, 0.8519, 0.4259, 0.4748, 0.5309, 0.5388, 0.4373, 0.38, 0.3162, 0.3253, 0.76, 0.2143, 0.0, 0.0449, 0.4737, 0.2674, 0.3677, 0.2759, 0.1989, 0.4688, 0.3774, 0.3478, 0.5457, 0.1793, 0.5323, 0.4534, 0.461, 0.3552, 0.7593, 0.4185, 0.5167, 0.268, 0.4923, 0.5056, 0.585, 0.5753, nan, 0.4431, 0.479, 0.2713, ...]\n[right]: [0.0333, 0.5922, 0.299, 0.6988, 0.0158, 0.7825, 0.7255, 0.7823, 0.5328, 0.8507, 0.7983, 0.4661, 0.028, 0.3046, 0.6408, 0.6979, 0.3874, 0.6921, 0.8957, 0.6273, 0.863, 0.1956, 0.3543, 0.6388, 0.7419, 0.3337, 0.6834, 0.5857, 0.6696, 0.6528, 0.7553, 0.1511, 0.4421, 0.6920000000000001, 0.5727, 0.0169, 0.6479, 0.7266, 0.7912, 0.7123, 0.867, 0.0059, 0.5441, 0.7976, 0.5106, 0.2504, 0.8183, 0.0106, 0.5613, 0.7827, 0.6149, 0.6733, 0.6176, 0.0748, 0.0647, 0.3951, 0.5132, 0.0035, 0.4333, 0.8009, 0.5747, 0.8519, 0.4259, 0.4748, 0.5309, 0.5388, 0.4373, 0.38, 0.3162, 0.3253, 0.76, 0.2143, 0.0, 0.0449, 0.4737, 0.2674, 0.3677, 0.2759, 0.1989, 0.4688, 0.3774, 0.3478, 0.5457, 0.1793, 0.5323, 0.4534, 0.461, 0.3552, 0.7593, 0.4185, 0.5167, 0.268, 0.4923, 0.5056, 0.585, 0.5753, nan, 0.4431, 0.479, 0.2713, ...]",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mAssertionError\u001b[0m                            Traceback (most recent call last)",
      "\u001b[1;32m<ipython-input-60-8a388ea2fc82>\u001b[0m in \u001b[0;36m<module>\u001b[1;34m\u001b[0m\n\u001b[0;32m      1\u001b[0m \u001b[0mnew_college_ugds_\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mcollege_ugds_\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0mcopy\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mdeep\u001b[0m\u001b[1;33m=\u001b[0m\u001b[1;32mTrue\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;31m# 深copy，否则引用的话改一个另一个会跟着变。\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m      2\u001b[0m \u001b[0mnew_college_ugds_\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'UGDS_WHITE'\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;34m'Alabama A & M University'\u001b[0m\u001b[1;33m]\u001b[0m \u001b[1;33m=\u001b[0m \u001b[1;36m0.04\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m----> 3\u001b[1;33m \u001b[0massert_frame_equal\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mnew_college_ugds_\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mcollege_ugds_\u001b[0m\u001b[1;33m)\u001b[0m \u001b[1;31m# 不一致会抛异常\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m",
      "\u001b[1;32mc:\\users\\lin\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\pandas\\_testing.py\u001b[0m in \u001b[0;36massert_frame_equal\u001b[1;34m(left, right, check_dtype, check_index_type, check_column_type, check_frame_type, check_less_precise, check_names, by_blocks, check_exact, check_datetimelike_compat, check_categorical, check_like, obj)\u001b[0m\n\u001b[0;32m   1370\u001b[0m             \u001b[0mlcol\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mleft\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0miloc\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mi\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1371\u001b[0m             \u001b[0mrcol\u001b[0m \u001b[1;33m=\u001b[0m \u001b[0mright\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0miloc\u001b[0m\u001b[1;33m[\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mi\u001b[0m\u001b[1;33m]\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1372\u001b[1;33m             assert_series_equal(\n\u001b[0m\u001b[0;32m   1373\u001b[0m                 \u001b[0mlcol\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1374\u001b[0m                 \u001b[0mrcol\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mc:\\users\\lin\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\pandas\\_testing.py\u001b[0m in \u001b[0;36massert_series_equal\u001b[1;34m(left, right, check_dtype, check_index_type, check_series_type, check_less_precise, check_names, check_exact, check_datetimelike_compat, check_categorical, check_category_order, obj)\u001b[0m\n\u001b[0;32m   1184\u001b[0m         \u001b[0massert_extension_array_equal\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mleft\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0marray\u001b[0m\u001b[1;33m,\u001b[0m \u001b[0mright\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0marray\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1185\u001b[0m     \u001b[1;32melse\u001b[0m\u001b[1;33m:\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m-> 1186\u001b[1;33m         _testing.assert_almost_equal(\n\u001b[0m\u001b[0;32m   1187\u001b[0m             \u001b[0mleft\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_internal_get_values\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m   1188\u001b[0m             \u001b[0mright\u001b[0m\u001b[1;33m.\u001b[0m\u001b[0m_internal_get_values\u001b[0m\u001b[1;33m(\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m,\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;32mpandas\\_libs\\testing.pyx\u001b[0m in \u001b[0;36mpandas._libs.testing.assert_almost_equal\u001b[1;34m()\u001b[0m\n",
      "\u001b[1;32mpandas\\_libs\\testing.pyx\u001b[0m in \u001b[0;36mpandas._libs.testing.assert_almost_equal\u001b[1;34m()\u001b[0m\n",
      "\u001b[1;32mc:\\users\\lin\\appdata\\local\\programs\\python\\python38-32\\lib\\site-packages\\pandas\\_testing.py\u001b[0m in \u001b[0;36mraise_assert_detail\u001b[1;34m(obj, message, left, right, diff)\u001b[0m\n\u001b[0;32m    913\u001b[0m         \u001b[0mmsg\u001b[0m \u001b[1;33m+=\u001b[0m \u001b[1;34mf\"\\n[diff]: {diff}\"\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    914\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[1;32m--> 915\u001b[1;33m     \u001b[1;32mraise\u001b[0m \u001b[0mAssertionError\u001b[0m\u001b[1;33m(\u001b[0m\u001b[0mmsg\u001b[0m\u001b[1;33m)\u001b[0m\u001b[1;33m\u001b[0m\u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0m\u001b[0;32m    916\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n\u001b[0;32m    917\u001b[0m \u001b[1;33m\u001b[0m\u001b[0m\n",
      "\u001b[1;31mAssertionError\u001b[0m: DataFrame.iloc[:, 0] (column name=\"UGDS_WHITE\") are different\n\nDataFrame.iloc[:, 0] (column name=\"UGDS_WHITE\") values are different (0.01327 %)\n[left]:  [0.04, 0.5922, 0.299, 0.6988, 0.0158, 0.7825, 0.7255, 0.7823, 0.5328, 0.8507, 0.7983, 0.4661, 0.028, 0.3046, 0.6408, 0.6979, 0.3874, 0.6921, 0.8957, 0.6273, 0.863, 0.1956, 0.3543, 0.6388, 0.7419, 0.3337, 0.6834, 0.5857, 0.6696, 0.6528, 0.7553, 0.1511, 0.4421, 0.6920000000000001, 0.5727, 0.0169, 0.6479, 0.7266, 0.7912, 0.7123, 0.867, 0.0059, 0.5441, 0.7976, 0.5106, 0.2504, 0.8183, 0.0106, 0.5613, 0.7827, 0.6149, 0.6733, 0.6176, 0.0748, 0.0647, 0.3951, 0.5132, 0.0035, 0.4333, 0.8009, 0.5747, 0.8519, 0.4259, 0.4748, 0.5309, 0.5388, 0.4373, 0.38, 0.3162, 0.3253, 0.76, 0.2143, 0.0, 0.0449, 0.4737, 0.2674, 0.3677, 0.2759, 0.1989, 0.4688, 0.3774, 0.3478, 0.5457, 0.1793, 0.5323, 0.4534, 0.461, 0.3552, 0.7593, 0.4185, 0.5167, 0.268, 0.4923, 0.5056, 0.585, 0.5753, nan, 0.4431, 0.479, 0.2713, ...]\n[right]: [0.0333, 0.5922, 0.299, 0.6988, 0.0158, 0.7825, 0.7255, 0.7823, 0.5328, 0.8507, 0.7983, 0.4661, 0.028, 0.3046, 0.6408, 0.6979, 0.3874, 0.6921, 0.8957, 0.6273, 0.863, 0.1956, 0.3543, 0.6388, 0.7419, 0.3337, 0.6834, 0.5857, 0.6696, 0.6528, 0.7553, 0.1511, 0.4421, 0.6920000000000001, 0.5727, 0.0169, 0.6479, 0.7266, 0.7912, 0.7123, 0.867, 0.0059, 0.5441, 0.7976, 0.5106, 0.2504, 0.8183, 0.0106, 0.5613, 0.7827, 0.6149, 0.6733, 0.6176, 0.0748, 0.0647, 0.3951, 0.5132, 0.0035, 0.4333, 0.8009, 0.5747, 0.8519, 0.4259, 0.4748, 0.5309, 0.5388, 0.4373, 0.38, 0.3162, 0.3253, 0.76, 0.2143, 0.0, 0.0449, 0.4737, 0.2674, 0.3677, 0.2759, 0.1989, 0.4688, 0.3774, 0.3478, 0.5457, 0.1793, 0.5323, 0.4534, 0.461, 0.3552, 0.7593, 0.4185, 0.5167, 0.268, 0.4923, 0.5056, 0.585, 0.5753, nan, 0.4431, 0.479, 0.2713, ...]"
     ]
    }
   ],
   "source": [
    "new_college_ugds_ = college_ugds_.copy(deep=True) # 深copy，否则引用的话改一个另一个会跟着变。\n",
    "new_college_ugds_['UGDS_WHITE']['Alabama A & M University'] = 0.04\n",
    "assert_frame_equal(new_college_ugds_, college_ugds_) # 不一致会抛异常"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>UGDS_WHITE</th>\n",
       "      <th>UGDS_BLACK</th>\n",
       "      <th>UGDS_HISP</th>\n",
       "      <th>UGDS_ASIAN</th>\n",
       "      <th>UGDS_AIAN</th>\n",
       "      <th>UGDS_NHPI</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Alabama A &amp; M University</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama at Birmingham</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Amridge University</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama in Huntsville</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Alabama State University</th>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                     UGDS_WHITE  UGDS_BLACK  UGDS_HISP  \\\n",
       "INSTNM                                                                   \n",
       "Alabama A & M University                  False       False      False   \n",
       "University of Alabama at Birmingham       False       False      False   \n",
       "Amridge University                        False       False      False   \n",
       "University of Alabama in Huntsville       False       False      False   \n",
       "Alabama State University                  False       False      False   \n",
       "\n",
       "                                     UGDS_ASIAN  UGDS_AIAN  UGDS_NHPI  \\\n",
       "INSTNM                                                                  \n",
       "Alabama A & M University                   True      False       True   \n",
       "University of Alabama at Birmingham       False      False      False   \n",
       "Amridge University                        False      False      False   \n",
       "University of Alabama in Huntsville       False      False      False   \n",
       "Alabama State University                   True      False      False   \n",
       "\n",
       "                                     UGDS_2MOR  UGDS_NRA  UGDS_UNKN  \n",
       "INSTNM                                                               \n",
       "Alabama A & M University                 False     False      False  \n",
       "University of Alabama at Birmingham      False     False      False  \n",
       "Amridge University                       False     False      False  \n",
       "University of Alabama in Huntsville      False     False      False  \n",
       "Alabama State University                 False     False      False  "
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college_ugds_.eq(.0019).head() # eq = equal，判断元素是否等于某个值。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## DataFrame数据操作的方向性"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>UGDS_WHITE</th>\n",
       "      <th>UGDS_BLACK</th>\n",
       "      <th>UGDS_HISP</th>\n",
       "      <th>UGDS_ASIAN</th>\n",
       "      <th>UGDS_AIAN</th>\n",
       "      <th>UGDS_NHPI</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Alabama A &amp; M University</th>\n",
       "      <td>0.0333</td>\n",
       "      <td>0.9353</td>\n",
       "      <td>0.0055</td>\n",
       "      <td>0.0019</td>\n",
       "      <td>0.0024</td>\n",
       "      <td>0.0019</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0059</td>\n",
       "      <td>0.0138</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama at Birmingham</th>\n",
       "      <td>0.5922</td>\n",
       "      <td>0.2600</td>\n",
       "      <td>0.0283</td>\n",
       "      <td>0.0518</td>\n",
       "      <td>0.0022</td>\n",
       "      <td>0.0007</td>\n",
       "      <td>0.0368</td>\n",
       "      <td>0.0179</td>\n",
       "      <td>0.0100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Amridge University</th>\n",
       "      <td>0.2990</td>\n",
       "      <td>0.4192</td>\n",
       "      <td>0.0069</td>\n",
       "      <td>0.0034</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.2715</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama in Huntsville</th>\n",
       "      <td>0.6988</td>\n",
       "      <td>0.1255</td>\n",
       "      <td>0.0382</td>\n",
       "      <td>0.0376</td>\n",
       "      <td>0.0143</td>\n",
       "      <td>0.0002</td>\n",
       "      <td>0.0172</td>\n",
       "      <td>0.0332</td>\n",
       "      <td>0.0350</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Alabama State University</th>\n",
       "      <td>0.0158</td>\n",
       "      <td>0.9208</td>\n",
       "      <td>0.0121</td>\n",
       "      <td>0.0019</td>\n",
       "      <td>0.0010</td>\n",
       "      <td>0.0006</td>\n",
       "      <td>0.0098</td>\n",
       "      <td>0.0243</td>\n",
       "      <td>0.0137</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                     UGDS_WHITE  UGDS_BLACK  UGDS_HISP  \\\n",
       "INSTNM                                                                   \n",
       "Alabama A & M University                 0.0333      0.9353     0.0055   \n",
       "University of Alabama at Birmingham      0.5922      0.2600     0.0283   \n",
       "Amridge University                       0.2990      0.4192     0.0069   \n",
       "University of Alabama in Huntsville      0.6988      0.1255     0.0382   \n",
       "Alabama State University                 0.0158      0.9208     0.0121   \n",
       "\n",
       "                                     UGDS_ASIAN  UGDS_AIAN  UGDS_NHPI  \\\n",
       "INSTNM                                                                  \n",
       "Alabama A & M University                 0.0019     0.0024     0.0019   \n",
       "University of Alabama at Birmingham      0.0518     0.0022     0.0007   \n",
       "Amridge University                       0.0034     0.0000     0.0000   \n",
       "University of Alabama in Huntsville      0.0376     0.0143     0.0002   \n",
       "Alabama State University                 0.0019     0.0010     0.0006   \n",
       "\n",
       "                                     UGDS_2MOR  UGDS_NRA  UGDS_UNKN  \n",
       "INSTNM                                                               \n",
       "Alabama A & M University                0.0000    0.0059     0.0138  \n",
       "University of Alabama at Birmingham     0.0368    0.0179     0.0100  \n",
       "Amridge University                      0.0000    0.0000     0.2715  \n",
       "University of Alabama in Huntsville     0.0172    0.0332     0.0350  \n",
       "Alabama State University                0.0098    0.0243     0.0137  "
      ]
     },
     "execution_count": 62,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college = pd.read_csv('data/college.csv', index_col='INSTNM')\n",
    "college_ugds_ = college.filter(like='UGDS_')\n",
    "college_ugds_.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "UGDS_WHITE    6874\n",
       "UGDS_BLACK    6874\n",
       "UGDS_HISP     6874\n",
       "UGDS_ASIAN    6874\n",
       "              ... \n",
       "UGDS_NHPI     6874\n",
       "UGDS_2MOR     6874\n",
       "UGDS_NRA      6874\n",
       "UGDS_UNKN     6874\n",
       "Length: 9, dtype: int64"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college_ugds_.count() # 每一列有多少个元素值非空，默认axis=0。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "UGDS_WHITE    6874\n",
       "UGDS_BLACK    6874\n",
       "UGDS_HISP     6874\n",
       "UGDS_ASIAN    6874\n",
       "              ... \n",
       "UGDS_NHPI     6874\n",
       "UGDS_2MOR     6874\n",
       "UGDS_NRA      6874\n",
       "UGDS_UNKN     6874\n",
       "Length: 9, dtype: int64"
      ]
     },
     "execution_count": 64,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college_ugds_.count(axis=0) # 0代表按列操作，一列列进行统计元素值非空的数量。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "INSTNM\n",
       "Alabama A & M University                                  9\n",
       "University of Alabama at Birmingham                       9\n",
       "Amridge University                                        9\n",
       "University of Alabama in Huntsville                       9\n",
       "                                                         ..\n",
       "Rasmussen College - Overland Park                         0\n",
       "National Personal Training Institute of Cleveland         0\n",
       "Bay Area Medical Academy - San Jose Satellite Location    0\n",
       "Excel Learning Center-San Antonio South                   0\n",
       "Length: 7535, dtype: int64"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college_ugds_.count(axis=1) # 1代表按行操作，一列列进行统计元素值非空的数量。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "UGDS_WHITE    6874\n",
       "UGDS_BLACK    6874\n",
       "UGDS_HISP     6874\n",
       "UGDS_ASIAN    6874\n",
       "              ... \n",
       "UGDS_NHPI     6874\n",
       "UGDS_2MOR     6874\n",
       "UGDS_NRA      6874\n",
       "UGDS_UNKN     6874\n",
       "Length: 9, dtype: int64"
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college_ugds_.count(axis='index') # 等于0，也可以理解成沿着行索引的方向从上往下数。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 67,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "INSTNM\n",
       "Alabama A & M University                                  9\n",
       "University of Alabama at Birmingham                       9\n",
       "Amridge University                                        9\n",
       "University of Alabama in Huntsville                       9\n",
       "                                                         ..\n",
       "Rasmussen College - Overland Park                         0\n",
       "National Personal Training Institute of Cleveland         0\n",
       "Bay Area Medical Academy - San Jose Satellite Location    0\n",
       "Excel Learning Center-San Antonio South                   0\n",
       "Length: 7535, dtype: int64"
      ]
     },
     "execution_count": 67,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college_ugds_.count(axis='columns') # 等于1，也可以理解成沿着列的方向从左往右数。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "INSTNM\n",
       "Alabama A & M University                                  1.0000\n",
       "University of Alabama at Birmingham                       0.9999\n",
       "Amridge University                                        1.0000\n",
       "University of Alabama in Huntsville                       1.0000\n",
       "                                                           ...  \n",
       "Rasmussen College - Overland Park                         0.0000\n",
       "National Personal Training Institute of Cleveland         0.0000\n",
       "Bay Area Medical Academy - San Jose Satellite Location    0.0000\n",
       "Excel Learning Center-San Antonio South                   0.0000\n",
       "Length: 7535, dtype: float64"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college_ugds_.sum(axis='columns') # 对每一行元素求和"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 69,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "UGDS_WHITE    0.55570\n",
       "UGDS_BLACK    0.10005\n",
       "UGDS_HISP     0.07140\n",
       "UGDS_ASIAN    0.01290\n",
       "               ...   \n",
       "UGDS_NHPI     0.00000\n",
       "UGDS_2MOR     0.01750\n",
       "UGDS_NRA      0.00000\n",
       "UGDS_UNKN     0.01430\n",
       "Length: 9, dtype: float64"
      ]
     },
     "execution_count": 69,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college_ugds_.median(axis='index') # 对每一列元素求平均值"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 70,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>UGDS_WHITE</th>\n",
       "      <th>UGDS_BLACK</th>\n",
       "      <th>UGDS_HISP</th>\n",
       "      <th>UGDS_ASIAN</th>\n",
       "      <th>UGDS_AIAN</th>\n",
       "      <th>UGDS_NHPI</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Alabama A &amp; M University</th>\n",
       "      <td>0.0333</td>\n",
       "      <td>0.9686</td>\n",
       "      <td>0.9741</td>\n",
       "      <td>0.9760</td>\n",
       "      <td>0.9784</td>\n",
       "      <td>0.9803</td>\n",
       "      <td>0.9803</td>\n",
       "      <td>0.9862</td>\n",
       "      <td>1.0000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama at Birmingham</th>\n",
       "      <td>0.5922</td>\n",
       "      <td>0.8522</td>\n",
       "      <td>0.8805</td>\n",
       "      <td>0.9323</td>\n",
       "      <td>0.9345</td>\n",
       "      <td>0.9352</td>\n",
       "      <td>0.9720</td>\n",
       "      <td>0.9899</td>\n",
       "      <td>0.9999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Amridge University</th>\n",
       "      <td>0.2990</td>\n",
       "      <td>0.7182</td>\n",
       "      <td>0.7251</td>\n",
       "      <td>0.7285</td>\n",
       "      <td>0.7285</td>\n",
       "      <td>0.7285</td>\n",
       "      <td>0.7285</td>\n",
       "      <td>0.7285</td>\n",
       "      <td>1.0000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama in Huntsville</th>\n",
       "      <td>0.6988</td>\n",
       "      <td>0.8243</td>\n",
       "      <td>0.8625</td>\n",
       "      <td>0.9001</td>\n",
       "      <td>0.9144</td>\n",
       "      <td>0.9146</td>\n",
       "      <td>0.9318</td>\n",
       "      <td>0.9650</td>\n",
       "      <td>1.0000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Alabama State University</th>\n",
       "      <td>0.0158</td>\n",
       "      <td>0.9366</td>\n",
       "      <td>0.9487</td>\n",
       "      <td>0.9506</td>\n",
       "      <td>0.9516</td>\n",
       "      <td>0.9522</td>\n",
       "      <td>0.9620</td>\n",
       "      <td>0.9863</td>\n",
       "      <td>1.0000</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                     UGDS_WHITE  UGDS_BLACK  UGDS_HISP  \\\n",
       "INSTNM                                                                   \n",
       "Alabama A & M University                 0.0333      0.9686     0.9741   \n",
       "University of Alabama at Birmingham      0.5922      0.8522     0.8805   \n",
       "Amridge University                       0.2990      0.7182     0.7251   \n",
       "University of Alabama in Huntsville      0.6988      0.8243     0.8625   \n",
       "Alabama State University                 0.0158      0.9366     0.9487   \n",
       "\n",
       "                                     UGDS_ASIAN  UGDS_AIAN  UGDS_NHPI  \\\n",
       "INSTNM                                                                  \n",
       "Alabama A & M University                 0.9760     0.9784     0.9803   \n",
       "University of Alabama at Birmingham      0.9323     0.9345     0.9352   \n",
       "Amridge University                       0.7285     0.7285     0.7285   \n",
       "University of Alabama in Huntsville      0.9001     0.9144     0.9146   \n",
       "Alabama State University                 0.9506     0.9516     0.9522   \n",
       "\n",
       "                                     UGDS_2MOR  UGDS_NRA  UGDS_UNKN  \n",
       "INSTNM                                                               \n",
       "Alabama A & M University                0.9803    0.9862     1.0000  \n",
       "University of Alabama at Birmingham     0.9720    0.9899     0.9999  \n",
       "Amridge University                      0.7285    0.7285     1.0000  \n",
       "University of Alabama in Huntsville     0.9318    0.9650     1.0000  \n",
       "Alabama State University                0.9620    0.9863     1.0000  "
      ]
     },
     "execution_count": 70,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 沿着行的方向累加\n",
    "# 已第一行的前几个值为例[0.0333, 0.9353, 0.0055, 0.0019, ...]\n",
    "# [0.0333, 0.0333 + 0.9353 = 0.9686, 0.9686 + 0.0055 = 0.9741, 0.9741 + 0.0019 = 0.976, ...]\n",
    "college_ugds_cumsum = college_ugds_.cumsum(axis=1)\n",
    "college_ugds_cumsum.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 71,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>UGDS_WHITE</th>\n",
       "      <th>UGDS_BLACK</th>\n",
       "      <th>UGDS_HISP</th>\n",
       "      <th>UGDS_ASIAN</th>\n",
       "      <th>UGDS_AIAN</th>\n",
       "      <th>UGDS_NHPI</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>New Beginning College of Cosmetology</th>\n",
       "      <td>0.8957</td>\n",
       "      <td>0.9305</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Virginia University of Lynchburg</th>\n",
       "      <td>0.0120</td>\n",
       "      <td>0.9921</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Turning Point Beauty College</th>\n",
       "      <td>0.1915</td>\n",
       "      <td>0.2341</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>First Coast Barber Academy</th>\n",
       "      <td>0.1667</td>\n",
       "      <td>0.9445</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "      <td>1.0001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Rasmussen College - Overland Park</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>National Personal Training Institute of Cleveland</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Bay Area Medical Academy - San Jose Satellite Location</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Excel Learning Center-San Antonio South</th>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>7535 rows × 9 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                    UGDS_WHITE  UGDS_BLACK  \\\n",
       "INSTNM                                                                       \n",
       "New Beginning College of Cosmetology                    0.8957      0.9305   \n",
       "Virginia University of Lynchburg                        0.0120      0.9921   \n",
       "Turning Point Beauty College                            0.1915      0.2341   \n",
       "First Coast Barber Academy                              0.1667      0.9445   \n",
       "...                                                        ...         ...   \n",
       "Rasmussen College - Overland Park                          NaN         NaN   \n",
       "National Personal Training Institute of Cleveland          NaN         NaN   \n",
       "Bay Area Medical Academy - San Jose Satellite L...         NaN         NaN   \n",
       "Excel Learning Center-San Antonio South                    NaN         NaN   \n",
       "\n",
       "                                                    UGDS_HISP  UGDS_ASIAN  \\\n",
       "INSTNM                                                                      \n",
       "New Beginning College of Cosmetology                   1.0001      1.0001   \n",
       "Virginia University of Lynchburg                       1.0001      1.0001   \n",
       "Turning Point Beauty College                           1.0001      1.0001   \n",
       "First Coast Barber Academy                             1.0001      1.0001   \n",
       "...                                                       ...         ...   \n",
       "Rasmussen College - Overland Park                         NaN         NaN   \n",
       "National Personal Training Institute of Cleveland         NaN         NaN   \n",
       "Bay Area Medical Academy - San Jose Satellite L...        NaN         NaN   \n",
       "Excel Learning Center-San Antonio South                   NaN         NaN   \n",
       "\n",
       "                                                    UGDS_AIAN  UGDS_NHPI  \\\n",
       "INSTNM                                                                     \n",
       "New Beginning College of Cosmetology                   1.0001     1.0001   \n",
       "Virginia University of Lynchburg                       1.0001     1.0001   \n",
       "Turning Point Beauty College                           1.0001     1.0001   \n",
       "First Coast Barber Academy                             1.0001     1.0001   \n",
       "...                                                       ...        ...   \n",
       "Rasmussen College - Overland Park                         NaN        NaN   \n",
       "National Personal Training Institute of Cleveland         NaN        NaN   \n",
       "Bay Area Medical Academy - San Jose Satellite L...        NaN        NaN   \n",
       "Excel Learning Center-San Antonio South                   NaN        NaN   \n",
       "\n",
       "                                                    UGDS_2MOR  UGDS_NRA  \\\n",
       "INSTNM                                                                    \n",
       "New Beginning College of Cosmetology                   1.0001    1.0001   \n",
       "Virginia University of Lynchburg                       1.0001    1.0001   \n",
       "Turning Point Beauty College                           1.0001    1.0001   \n",
       "First Coast Barber Academy                             1.0001    1.0001   \n",
       "...                                                       ...       ...   \n",
       "Rasmussen College - Overland Park                         NaN       NaN   \n",
       "National Personal Training Institute of Cleveland         NaN       NaN   \n",
       "Bay Area Medical Academy - San Jose Satellite L...        NaN       NaN   \n",
       "Excel Learning Center-San Antonio South                   NaN       NaN   \n",
       "\n",
       "                                                    UGDS_UNKN  \n",
       "INSTNM                                                         \n",
       "New Beginning College of Cosmetology                   1.0001  \n",
       "Virginia University of Lynchburg                       1.0001  \n",
       "Turning Point Beauty College                           1.0001  \n",
       "First Coast Barber Academy                             1.0001  \n",
       "...                                                       ...  \n",
       "Rasmussen College - Overland Park                         NaN  \n",
       "National Personal Training Institute of Cleveland         NaN  \n",
       "Bay Area Medical Academy - San Jose Satellite L...        NaN  \n",
       "Excel Learning Center-San Antonio South                   NaN  \n",
       "\n",
       "[7535 rows x 9 columns]"
      ]
     },
     "execution_count": 71,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college_ugds_cumsum.sort_values('UGDS_HISP', ascending=False) # 已UGDS_HISP为基准降序排序"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 计算大学校园多元化"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Diversity Index</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>School</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Rutgers University--Newark  Newark, NJ</th>\n",
       "      <td>0.76</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Andrews University  Berrien Springs, MI</th>\n",
       "      <td>0.74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Stanford University  Stanford, CA</th>\n",
       "      <td>0.74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Houston  Houston, TX</th>\n",
       "      <td>0.74</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>San Francisco State University  San Francisco, CA</th>\n",
       "      <td>0.73</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Illinois--Chicago  Chicago, IL</th>\n",
       "      <td>0.73</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>New Jersey Institute of Technology  Newark, NJ</th>\n",
       "      <td>0.72</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Texas Woman's University  Denton, TX</th>\n",
       "      <td>0.72</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>10 rows × 1 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                   Diversity Index\n",
       "School                                                            \n",
       "Rutgers University--Newark  Newark, NJ                        0.76\n",
       "Andrews University  Berrien Springs, MI                       0.74\n",
       "Stanford University  Stanford, CA                             0.74\n",
       "University of Houston  Houston, TX                            0.74\n",
       "...                                                            ...\n",
       "San Francisco State University  San Francisco, CA             0.73\n",
       "University of Illinois--Chicago  Chicago, IL                  0.73\n",
       "New Jersey Institute of Technology  Newark, NJ                0.72\n",
       "Texas Woman's University  Denton, TX                          0.72\n",
       "\n",
       "[10 rows x 1 columns]"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "pd.read_csv('data/college_diversity.csv', index_col='School') # 使用学校名称做为索引"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 73,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>UGDS_WHITE</th>\n",
       "      <th>UGDS_BLACK</th>\n",
       "      <th>UGDS_HISP</th>\n",
       "      <th>UGDS_ASIAN</th>\n",
       "      <th>UGDS_AIAN</th>\n",
       "      <th>UGDS_NHPI</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Alabama A &amp; M University</th>\n",
       "      <td>0.0333</td>\n",
       "      <td>0.9353</td>\n",
       "      <td>0.0055</td>\n",
       "      <td>0.0019</td>\n",
       "      <td>0.0024</td>\n",
       "      <td>0.0019</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0059</td>\n",
       "      <td>0.0138</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama at Birmingham</th>\n",
       "      <td>0.5922</td>\n",
       "      <td>0.2600</td>\n",
       "      <td>0.0283</td>\n",
       "      <td>0.0518</td>\n",
       "      <td>0.0022</td>\n",
       "      <td>0.0007</td>\n",
       "      <td>0.0368</td>\n",
       "      <td>0.0179</td>\n",
       "      <td>0.0100</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Amridge University</th>\n",
       "      <td>0.2990</td>\n",
       "      <td>0.4192</td>\n",
       "      <td>0.0069</td>\n",
       "      <td>0.0034</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.2715</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama in Huntsville</th>\n",
       "      <td>0.6988</td>\n",
       "      <td>0.1255</td>\n",
       "      <td>0.0382</td>\n",
       "      <td>0.0376</td>\n",
       "      <td>0.0143</td>\n",
       "      <td>0.0002</td>\n",
       "      <td>0.0172</td>\n",
       "      <td>0.0332</td>\n",
       "      <td>0.0350</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Alabama State University</th>\n",
       "      <td>0.0158</td>\n",
       "      <td>0.9208</td>\n",
       "      <td>0.0121</td>\n",
       "      <td>0.0019</td>\n",
       "      <td>0.0010</td>\n",
       "      <td>0.0006</td>\n",
       "      <td>0.0098</td>\n",
       "      <td>0.0243</td>\n",
       "      <td>0.0137</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                     UGDS_WHITE  UGDS_BLACK  UGDS_HISP  \\\n",
       "INSTNM                                                                   \n",
       "Alabama A & M University                 0.0333      0.9353     0.0055   \n",
       "University of Alabama at Birmingham      0.5922      0.2600     0.0283   \n",
       "Amridge University                       0.2990      0.4192     0.0069   \n",
       "University of Alabama in Huntsville      0.6988      0.1255     0.0382   \n",
       "Alabama State University                 0.0158      0.9208     0.0121   \n",
       "\n",
       "                                     UGDS_ASIAN  UGDS_AIAN  UGDS_NHPI  \\\n",
       "INSTNM                                                                  \n",
       "Alabama A & M University                 0.0019     0.0024     0.0019   \n",
       "University of Alabama at Birmingham      0.0518     0.0022     0.0007   \n",
       "Amridge University                       0.0034     0.0000     0.0000   \n",
       "University of Alabama in Huntsville      0.0376     0.0143     0.0002   \n",
       "Alabama State University                 0.0019     0.0010     0.0006   \n",
       "\n",
       "                                     UGDS_2MOR  UGDS_NRA  UGDS_UNKN  \n",
       "INSTNM                                                               \n",
       "Alabama A & M University                0.0000    0.0059     0.0138  \n",
       "University of Alabama at Birmingham     0.0368    0.0179     0.0100  \n",
       "Amridge University                      0.0000    0.0000     0.2715  \n",
       "University of Alabama in Huntsville     0.0172    0.0332     0.0350  \n",
       "Alabama State University                0.0098    0.0243     0.0137  "
      ]
     },
     "execution_count": 73,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college = pd.read_csv('data/college.csv', index_col='INSTNM')\n",
    "college_ugds_ = college.filter(like='UGDS_')\n",
    "college_ugds_.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 74,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "INSTNM\n",
       "Excel Learning Center-San Antonio South         9\n",
       "Philadelphia College of Osteopathic Medicine    9\n",
       "Assemblies of God Theological Seminary          9\n",
       "Episcopal Divinity School                       9\n",
       "Phillips Graduate Institute                     9\n",
       "dtype: int64"
      ]
     },
     "execution_count": 74,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college_ugds_.isnull().sum(axis=1).sort_values(ascending=False).head() # 统计每行空值元素的个数，并按降序排序。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "metadata": {},
   "outputs": [],
   "source": [
    "college_ugds_ = college_ugds_.dropna(how='all') # 删除所有包含空值的行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 76,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "UGDS_WHITE    0\n",
       "UGDS_BLACK    0\n",
       "UGDS_HISP     0\n",
       "UGDS_ASIAN    0\n",
       "             ..\n",
       "UGDS_NHPI     0\n",
       "UGDS_2MOR     0\n",
       "UGDS_NRA      0\n",
       "UGDS_UNKN     0\n",
       "Length: 9, dtype: int64"
      ]
     },
     "execution_count": 76,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college_ugds_.isnull().sum() # 因为包含空值的行已删除，所以结果都为0。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>UGDS_WHITE</th>\n",
       "      <th>UGDS_BLACK</th>\n",
       "      <th>UGDS_HISP</th>\n",
       "      <th>UGDS_ASIAN</th>\n",
       "      <th>UGDS_AIAN</th>\n",
       "      <th>UGDS_NHPI</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Alabama A &amp; M University</th>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama at Birmingham</th>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Amridge University</th>\n",
       "      <td>True</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>University of Alabama in Huntsville</th>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Alabama State University</th>\n",
       "      <td>False</td>\n",
       "      <td>True</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                     UGDS_WHITE  UGDS_BLACK  UGDS_HISP  \\\n",
       "INSTNM                                                                   \n",
       "Alabama A & M University                  False        True      False   \n",
       "University of Alabama at Birmingham        True        True      False   \n",
       "Amridge University                         True        True      False   \n",
       "University of Alabama in Huntsville        True       False      False   \n",
       "Alabama State University                  False        True      False   \n",
       "\n",
       "                                     UGDS_ASIAN  UGDS_AIAN  UGDS_NHPI  \\\n",
       "INSTNM                                                                  \n",
       "Alabama A & M University                  False      False      False   \n",
       "University of Alabama at Birmingham       False      False      False   \n",
       "Amridge University                        False      False      False   \n",
       "University of Alabama in Huntsville       False      False      False   \n",
       "Alabama State University                  False      False      False   \n",
       "\n",
       "                                     UGDS_2MOR  UGDS_NRA  UGDS_UNKN  \n",
       "INSTNM                                                               \n",
       "Alabama A & M University                 False     False      False  \n",
       "University of Alabama at Birmingham      False     False      False  \n",
       "Amridge University                       False     False       True  \n",
       "University of Alabama in Huntsville      False     False      False  \n",
       "Alabama State University                 False     False      False  "
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college_ugds_.ge(.15).head() # ge = greater equal (>=)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 78,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "INSTNM\n",
       "Alabama A & M University               1\n",
       "University of Alabama at Birmingham    2\n",
       "Amridge University                     3\n",
       "University of Alabama in Huntsville    1\n",
       "Alabama State University               1\n",
       "dtype: int64"
      ]
     },
     "execution_count": 78,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "diversity_metric = college_ugds_.ge(.15).sum(axis='columns') # 每一行从左往右求和，沿着列的方向从左往右。True按1处理。\n",
    "diversity_metric.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 79,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1    3042\n",
       "2    2884\n",
       "3     876\n",
       "4      63\n",
       "0       7\n",
       "5       2\n",
       "dtype: int64"
      ]
     },
     "execution_count": 79,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "diversity_metric.value_counts() # 根据值进行分组统计，1代表有1列的值大于0.15，4代表有4列的值大于0.15。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 80,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "INSTNM\n",
       "Regency Beauty Institute-Austin          5\n",
       "Central Texas Beauty College-Temple      5\n",
       "Sullivan and Cogliano Training Center    4\n",
       "Ambria College of Nursing                4\n",
       "Berkeley College-New York                4\n",
       "dtype: int64"
      ]
     },
     "execution_count": 80,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "diversity_metric.sort_values(ascending=False).head() # 降序排序"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>UGDS_WHITE</th>\n",
       "      <th>UGDS_BLACK</th>\n",
       "      <th>UGDS_HISP</th>\n",
       "      <th>UGDS_ASIAN</th>\n",
       "      <th>UGDS_AIAN</th>\n",
       "      <th>UGDS_NHPI</th>\n",
       "      <th>UGDS_2MOR</th>\n",
       "      <th>UGDS_NRA</th>\n",
       "      <th>UGDS_UNKN</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>INSTNM</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>Regency Beauty Institute-Austin</th>\n",
       "      <td>0.1867</td>\n",
       "      <td>0.2133</td>\n",
       "      <td>0.1600</td>\n",
       "      <td>0.0000</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.1733</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.2667</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Central Texas Beauty College-Temple</th>\n",
       "      <td>0.1616</td>\n",
       "      <td>0.2323</td>\n",
       "      <td>0.2626</td>\n",
       "      <td>0.0202</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.1717</td>\n",
       "      <td>0.0</td>\n",
       "      <td>0.1515</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                     UGDS_WHITE  UGDS_BLACK  UGDS_HISP  \\\n",
       "INSTNM                                                                   \n",
       "Regency Beauty Institute-Austin          0.1867      0.2133     0.1600   \n",
       "Central Texas Beauty College-Temple      0.1616      0.2323     0.2626   \n",
       "\n",
       "                                     UGDS_ASIAN  UGDS_AIAN  UGDS_NHPI  \\\n",
       "INSTNM                                                                  \n",
       "Regency Beauty Institute-Austin          0.0000        0.0        0.0   \n",
       "Central Texas Beauty College-Temple      0.0202        0.0        0.0   \n",
       "\n",
       "                                     UGDS_2MOR  UGDS_NRA  UGDS_UNKN  \n",
       "INSTNM                                                               \n",
       "Regency Beauty Institute-Austin         0.1733       0.0     0.2667  \n",
       "Central Texas Beauty College-Temple     0.1717       0.0     0.1515  "
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 注意：这里使用loc，与直接使用[]不同，变成了传统的先行后列，不指定列就是选择所有列。\n",
    "college_ugds_.loc[['Regency Beauty Institute-Austin', 'Central Texas Beauty College-Temple']]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 82,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "INSTNM\n",
       "Rutgers University-Newark         4\n",
       "Andrews University                3\n",
       "Stanford University               3\n",
       "University of Houston             3\n",
       "University of Nevada-Las Vegas    3\n",
       "dtype: int64"
      ]
     },
     "execution_count": 82,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "us_news_top = ['Rutgers University-Newark', \n",
    "               'Andrews University', \n",
    "               'Stanford University', \n",
    "               'University of Houston',\n",
    "               'University of Nevada-Las Vegas']\n",
    "diversity_metric.loc[us_news_top] # 根据行索引选择指定的行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "INSTNM\n",
       "Dewey University-Manati                               1.0\n",
       "Yeshiva and Kollel Harbotzas Torah                    1.0\n",
       "Mr Leon's School of Hair Design-Lewiston              1.0\n",
       "Dewey University-Bayamon                              1.0\n",
       "                                                     ... \n",
       "Monteclaro Escuela de Hoteleria y Artes Culinarias    1.0\n",
       "Yeshiva Shaar Hatorah                                 1.0\n",
       "Bais Medrash Elyon                                    1.0\n",
       "Yeshiva of Nitra Rabbinical College                   1.0\n",
       "Length: 10, dtype: float64"
      ]
     },
     "execution_count": 83,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college_ugds_.max(axis=1).sort_values(ascending=False).head(10) # 每一行取最大值，然后降序排序选取前10条数据。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 84,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "UGDS_WHITE: 0.0\n",
      "UGDS_BLACK: 0.0\n",
      "UGDS_HISP: 1.0\n",
      "UGDS_ASIAN: 0.0\n",
      "UGDS_AIAN: 0.0\n",
      "UGDS_NHPI: 0.0\n",
      "UGDS_2MOR: 0.0\n",
      "UGDS_NRA: 0.0\n",
      "UGDS_UNKN: 0.0\n"
     ]
    }
   ],
   "source": [
    "for c in college_ugds_.columns:\n",
    "    print(c + ': ' + str(college_ugds_[c]['Dewey University-Manati'])) # DataFrame的索引是先列后行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "UGDS_WHITE    0.0\n",
       "UGDS_BLACK    0.0\n",
       "UGDS_HISP     1.0\n",
       "UGDS_ASIAN    0.0\n",
       "             ... \n",
       "UGDS_NHPI     0.0\n",
       "UGDS_2MOR     0.0\n",
       "UGDS_NRA      0.0\n",
       "UGDS_UNKN     0.0\n",
       "Name: Dewey University-Manati, Length: 9, dtype: float64"
      ]
     },
     "execution_count": 85,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "college_ugds_.loc['Dewey University-Manati'] # 直接选取某一行"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 86,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "True"
      ]
     },
     "execution_count": 86,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(college_ugds_ > .01).all(axis=1).any() # 是否存在一行数据，每一列的值都大于0.01。"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.2"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
